├── src ├── Models │ ├── Roles │ │ ├── RoleTranslation.php │ │ ├── Roleable.php │ │ └── Role.php │ ├── Permissions │ │ ├── PermissionTranslation.php │ │ ├── Permissible.php │ │ └── Permission.php │ ├── Actions │ │ ├── Like.php │ │ ├── Follow.php │ │ ├── Favourite.php │ │ ├── Subscribe.php │ │ ├── Vote.php │ │ ├── Bookmark.php │ │ ├── Comment.php │ │ └── Review.php │ ├── UserPasswordHistory.php │ └── UserAgent.php ├── Middleware │ ├── Entrusted.php │ ├── EntrustedAny.php │ ├── Permitted.php │ └── PermittedAny.php ├── Classes │ └── Actions.php ├── database │ └── migrations │ │ ├── 2021_02_01_000029_create_roles_table.php │ │ ├── 2021_02_01_000026_create_permissions_table.php │ │ ├── 2021_02_01_000031_create_roleables_table.php │ │ ├── 2021_02_01_000077_create_likes_table.php │ │ ├── 2021_02_01_000028_create_permissibles_table.php │ │ ├── 2021_02_01_000078_create_follows_table.php │ │ ├── 2021_02_01_000079_create_favourites_table.php │ │ ├── 2021_02_01_000083_create_subscribes_table.php │ │ ├── 2021_02_01_000081_create_votes_table.php │ │ ├── 2021_02_01_000080_create_bookmarks_table.php │ │ ├── 2021_02_01_000030_create_role_translations_table.php │ │ ├── 2021_02_01_000084_create_comments_table.php │ │ ├── 2021_02_01_000027_create_permission_translations_table.php │ │ ├── 2021_02_01_000025_create_user_password_history_table.php │ │ ├── 2021_02_01_000082_create_reviews_table.php │ │ └── 2021_02_01_000024_create_user_agents_table.php ├── Traits │ ├── Password │ │ ├── HasHashedPassword.php │ │ └── HasPasswordHistory.php │ ├── Actions │ │ ├── Comment │ │ │ ├── isCommenter.php │ │ │ └── isCommentable.php │ │ ├── Like │ │ │ ├── isLiker.php │ │ │ └── isLikeable.php │ │ ├── Follow │ │ │ ├── isFollower.php │ │ │ └── isFollowable.php │ │ ├── Favourite │ │ │ ├── isFavorer.php │ │ │ └── isFavourable.php │ │ ├── Subscribe │ │ │ ├── isSubscriber.php │ │ │ └── isSubscribable.php │ │ ├── Bookmark │ │ │ ├── isBookmaker.php │ │ │ └── isBookmarkable.php │ │ ├── Review │ │ │ ├── isReviewer.php │ │ │ └── isReviewable.php │ │ └── Vote │ │ │ ├── isVoter.php │ │ │ └── isVotable.php │ ├── HasDevices.php │ ├── HasRoles.php │ └── HasPermissions.php ├── helpers.php └── UsersServiceProvider.php ├── composer.json └── README.md /src/Models/Roles/RoleTranslation.php: -------------------------------------------------------------------------------- 1 | user(); 21 | 22 | if (!$user || empty($roles) || !$user->entrusted($roles)) return abort(404); 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Middleware/EntrustedAny.php: -------------------------------------------------------------------------------- 1 | user(); 21 | 22 | if (!$user || empty($roles) || !$user->entrustedAny($roles)) return abort(404); 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Middleware/Permitted.php: -------------------------------------------------------------------------------- 1 | user(); 21 | if (!$user || empty($permissions) || !$user->permitted($permissions)) return abort(404); 22 | 23 | return $next($request); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Middleware/PermittedAny.php: -------------------------------------------------------------------------------- 1 | user(); 21 | if (!$user || empty($permissions) || !$user->permittedAny($permissions)) return abort(404); 22 | 23 | return $next($request); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Classes/Actions.php: -------------------------------------------------------------------------------- 1 | check() ? false : auth()->user()->{$action}(self::prepareParamsArray($list)); 12 | } 13 | 14 | /** 15 | * Prepare Roles & Permissions 16 | * 17 | * @param array $params 18 | * @return array 19 | */ 20 | private static function prepareParamsArray($params) 21 | { 22 | if (is_array($params[0])) $params = $params[0]; 23 | if (is_string($params)) $params = explode(',', $params); 24 | 25 | return $params; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Models/Actions/Like.php: -------------------------------------------------------------------------------- 1 | morphTo(); 25 | } 26 | 27 | /** 28 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 29 | */ 30 | public function liker() 31 | { 32 | return $this->morphTo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000029_create_roles_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('code', 50); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('roles'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Models/Actions/Follow.php: -------------------------------------------------------------------------------- 1 | morphTo(); 25 | } 26 | 27 | /** 28 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 29 | */ 30 | public function follower() 31 | { 32 | return $this->morphTo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Models/Actions/Favourite.php: -------------------------------------------------------------------------------- 1 | morphTo(); 25 | } 26 | 27 | /** 28 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 29 | */ 30 | public function favorer() 31 | { 32 | return $this->morphTo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000026_create_permissions_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('code', 50); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('permissions'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Models/Actions/Subscribe.php: -------------------------------------------------------------------------------- 1 | morphTo(); 25 | } 26 | 27 | /** 28 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 29 | */ 30 | public function subscriber() 31 | { 32 | return $this->morphTo(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Traits/Password/HasHashedPassword.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | trait HasHashedPassword 13 | { 14 | /** 15 | * Set uuid key on creating 16 | * 17 | * @return void 18 | */ 19 | public static function bootHasHashedPassword() 20 | { 21 | self::creating(function ($model) { 22 | if (!empty($model->password)) 23 | $model->password = Hash::make($model->password); 24 | }); 25 | 26 | self::updating(function ($model) { 27 | if ($model->isDirty('password') && !empty($model->password)) { 28 | $model->password = Hash::make($model->password); 29 | } 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000031_create_roleables_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('role_id'); 19 | $table->morphs('roleable'); 20 | 21 | // Relationships 22 | $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('roleables'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Models/Actions/Vote.php: -------------------------------------------------------------------------------- 1 | 'boolean']; 26 | 27 | /** 28 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 29 | */ 30 | public function votable() 31 | { 32 | return $this->morphTo(); 33 | } 34 | 35 | /** 36 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 37 | */ 38 | public function voter() 39 | { 40 | return $this->morphTo(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000077_create_likes_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('likeable_id'); 20 | $table->string('likeable_type'); 21 | 22 | $table->string('liker_id'); 23 | $table->string('liker_type'); 24 | 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('likes'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000028_create_permissibles_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('permission_id'); 19 | $table->morphs('permissible'); 20 | 21 | // Relationships 22 | $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade'); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('permissibles'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000078_create_follows_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('followable_id'); 20 | $table->string('followable_type'); 21 | 22 | $table->string('follower_id'); 23 | $table->string('follower_type'); 24 | 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('follows'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000079_create_favourites_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('favourable_id'); 20 | $table->string('favourable_type'); 21 | 22 | $table->string('favorer_id'); 23 | $table->string('favorer_type'); 24 | 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('favourites'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Models/Actions/Bookmark.php: -------------------------------------------------------------------------------- 1 | 'array']; 26 | 27 | /** 28 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 29 | */ 30 | public function bookmarkable() 31 | { 32 | return $this->morphTo(); 33 | } 34 | 35 | /** 36 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 37 | */ 38 | public function bookmarker() 39 | { 40 | return $this->morphTo(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000083_create_subscribes_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('subscribable_id'); 20 | $table->string('subscribable_type'); 21 | 22 | $table->string('subscriber_id'); 23 | $table->string('subscriber_type'); 24 | 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('subscribes'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000081_create_votes_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('votable_id'); 20 | $table->string('votable_type'); 21 | 22 | $table->string('voter_id'); 23 | $table->string('voter_type'); 24 | 25 | $table->boolean('vote')->default(true); 26 | $table->timestamps(); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('votes'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Models/Roles/Roleable.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class Roleable extends Model 15 | { 16 | /** 17 | * The attributes that are mass assignable. 18 | * 19 | * @var array 20 | */ 21 | protected $fillable = ['role_id']; 22 | 23 | /** 24 | * Indicates if the model should be timestamped. 25 | * 26 | * @var bool 27 | */ 28 | public $timestamps = false; 29 | 30 | /** 31 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 32 | */ 33 | public function role() 34 | { 35 | return $this->belongsTo(Role::class); 36 | } 37 | 38 | /** 39 | * Get the parent model 40 | */ 41 | public function roleable() 42 | { 43 | return $this->morphTo(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000080_create_bookmarks_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('bookmarkable_id'); 20 | $table->string('bookmarkable_type'); 21 | 22 | $table->string('bookmarker_id'); 23 | $table->string('bookmarker_type'); 24 | 25 | $table->json('data')->nullable(); 26 | $table->timestamps(); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('bookmarks'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000030_create_role_translations_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('title'); 19 | 20 | $table->string('locale')->index(); 21 | $table->unsignedBigInteger('role_id'); 22 | $table->unique(['role_id', 'locale']); 23 | $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('role_translations'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Models/Actions/Comment.php: -------------------------------------------------------------------------------- 1 | morphTo(); 31 | } 32 | 33 | /** 34 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 35 | */ 36 | public function commenter() 37 | { 38 | return $this->morphTo(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Models/Permissions/Permissible.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class Permissible extends Model 15 | { 16 | /** 17 | * The attributes that are mass assignable. 18 | * 19 | * @var array 20 | */ 21 | protected $fillable = ['permission_id']; 22 | 23 | /** 24 | * Indicates if the model should be timestamped. 25 | * 26 | * @var bool 27 | */ 28 | public $timestamps = false; 29 | 30 | /** 31 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 32 | */ 33 | public function permission() 34 | { 35 | return $this->belongsTo(Permission::class); 36 | } 37 | 38 | /** 39 | * Get the parent model 40 | */ 41 | public function permissible() 42 | { 43 | return $this->morphTo(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000084_create_comments_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('commentable_id'); 20 | $table->string('commentable_type'); 21 | 22 | $table->string('commenter_id'); 23 | $table->string('commenter_type'); 24 | 25 | $table->mediumText('comment'); 26 | 27 | $table->timestamps(); 28 | $table->softDeletes(); 29 | }); 30 | } 31 | 32 | /** 33 | * Reverse the migrations. 34 | * 35 | * @return void 36 | */ 37 | public function down() 38 | { 39 | Schema::dropIfExists('comments'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000027_create_permission_translations_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('title'); 19 | 20 | $table->string('locale')->index(); 21 | $table->unsignedBigInteger('permission_id'); 22 | $table->unique(['permission_id', 'locale']); 23 | $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('permission_translations'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000025_create_user_password_history_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('pass_from'); 19 | $table->string('pass_to'); 20 | $table->foreignId('agent_id'); 21 | $table->string('ip'); 22 | 23 | $table->morphs('user'); 24 | $table->timestamps(); 25 | 26 | // Relationships 27 | $table->foreign('agent_id')->references('id')->on('agents')->onDelete('cascade'); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | Schema::dropIfExists('user_password_history'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000082_create_reviews_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | 19 | $table->string('reviewable_id'); 20 | $table->string('reviewable_type'); 21 | 22 | $table->string('reviewer_id'); 23 | $table->string('reviewer_type'); 24 | 25 | $table->decimal('rate', 5, 2)->default(0); 26 | $table->string('comment')->nullable(); 27 | 28 | $table->boolean('published')->default(false); 29 | $table->timestamps(); 30 | }); 31 | } 32 | 33 | /** 34 | * Reverse the migrations. 35 | * 36 | * @return void 37 | */ 38 | public function down() 39 | { 40 | Schema::dropIfExists('reviews'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/database/migrations/2021_02_01_000024_create_user_agents_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->morphs('user'); 19 | $table->string('signature'); 20 | $table->foreignId('agent_id'); 21 | $table->unique(['user_id', 'user_type', 'signature', 'agent_id']); 22 | 23 | $table->string('ip'); 24 | $table->string('fcm_token')->nullable(); 25 | $table->timestamp('last_action_at'); 26 | $table->timestamps(); 27 | 28 | // Relationships 29 | $table->foreign('agent_id')->references('id')->on('agents')->onDelete('cascade'); 30 | }); 31 | } 32 | 33 | /** 34 | * Reverse the migrations. 35 | * 36 | * @return void 37 | */ 38 | public function down() 39 | { 40 | Schema::dropIfExists('user_agents'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Traits/Password/HasPasswordHistory.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | trait HasPasswordHistory 14 | { 15 | /** 16 | * Set uuid key on creating 17 | * 18 | * @return void 19 | */ 20 | public static function bootHasPasswordHistory() 21 | { 22 | self::saved(function ($model) { 23 | if ($model->isDirty('password') && !$model->wasRecentlyCreated) $model->passwordHistory()->create([ 24 | 'pass_from' => $model->getOriginal('password'), 25 | 'pass_to' => $model->password, 26 | 'ip' => agent()->ip, 27 | 'agent_id' => agent()->id 28 | ]); 29 | }); 30 | } 31 | 32 | /** 33 | * Get all user's Hashed-Passwords. 34 | * 35 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 36 | */ 37 | public function passwordHistory() 38 | { 39 | return $this->morphMany(UserPasswordHistory::class, 'user') 40 | ->with(['agent', 'agent.device', 'agent.browser', 'agent.operationSystem']); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Models/UserPasswordHistory.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class UserPasswordHistory extends Model 22 | { 23 | /** 24 | * The table associated with the model. 25 | * 26 | * @var string 27 | */ 28 | protected $table = 'user_password_history'; 29 | 30 | /** 31 | * The attributes that are mass assignable. 32 | * 33 | * @var array 34 | */ 35 | protected $fillable = ['pass_from', 'pass_to', 'agent_id', 'ip', 'user_id', 'user_type']; 36 | 37 | /** 38 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 39 | */ 40 | public function agent() 41 | { 42 | return $this->belongsTo(Agent::class); 43 | } 44 | 45 | /** 46 | * Getting User Model 47 | * 48 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 49 | */ 50 | public function user() 51 | { 52 | return $this->morphTo(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | 'float', 28 | 'published' => 'boolean' 29 | ]; 30 | 31 | /** 32 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 33 | */ 34 | public function reviewable() 35 | { 36 | return $this->morphTo(); 37 | } 38 | 39 | /** 40 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 41 | */ 42 | public function reviewer() 43 | { 44 | return $this->morphTo(); 45 | } 46 | 47 | /** 48 | * Publish This Rate 49 | * 50 | * @return boolean 51 | */ 52 | public function publish() 53 | { 54 | return $this->update(['published' => true]); 55 | } 56 | 57 | /** 58 | * Unpublish This Rate 59 | * 60 | * @return boolean 61 | */ 62 | public function unpublish() 63 | { 64 | return $this->update(['published' => false]); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Models/UserAgent.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class UserAgent extends Model 24 | { 25 | /** 26 | * The attributes that are mass assignable. 27 | * 28 | * @var array 29 | */ 30 | protected $fillable = ['agent_id', 'signature', 'fcm_token', 'ip', 'user_id', 'user_type', 'last_action_at']; 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | protected $casts = ['last_action_at' => 'datetime']; 36 | 37 | /** 38 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 39 | */ 40 | public function agent() 41 | { 42 | return $this->belongsTo(Agent::class); 43 | } 44 | 45 | /** 46 | * Getting User Model 47 | * 48 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 49 | */ 50 | public function user() 51 | { 52 | return $this->morphTo(); 53 | } 54 | 55 | /** 56 | * Refresh LAST-ACTION-AT 57 | * 58 | * @return boolean 59 | */ 60 | public function refresh() 61 | { 62 | return $this->update(['last_action_at' => Carbon::now()]); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Traits/Actions/Comment/isCommenter.php: -------------------------------------------------------------------------------- 1 | comments()->delete(); 20 | } else { 21 | $model->comments()->forceDelete(); 22 | } 23 | }); 24 | } 25 | 26 | /** 27 | * Comment Model 28 | * 29 | * @param Model $commentable 30 | * @param string $comment 31 | * @return boolean 32 | */ 33 | public function comment(Model $commentable, string $comment) 34 | { 35 | return $this->comments()->make(['comment' => $comment])->commentable()->associate($commentable)->save(); 36 | } 37 | 38 | /** 39 | * Has Commented By Commenter 40 | * 41 | * @param Model $commentable 42 | * @return boolean 43 | */ 44 | public function commented(Model $commentable) 45 | { 46 | return $this->comments()->where(['commentable_id' => $commentable->getKey(), 'commentable_type' => get_class($commentable)])->exists(); 47 | } 48 | 49 | /** 50 | * Comments List 51 | * 52 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 53 | */ 54 | public function comments() 55 | { 56 | return $this->morphMany(Comment::class, 'commenter'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pharaonic/laravel-users", 3 | "description": "Laravel Users (Roles & Permissions, Devices, Password: Auto Hashing & History, Actions: Likes, Rates, Subscribes, Votes, Follows, Favorites, Bookmarks).", 4 | "keywords": [ 5 | "laravel roles", 6 | "laravel permissions", 7 | "laravel user devices", 8 | "laravel user passwords", 9 | "laravel user passwords hashed", 10 | "laravel user passwords history", 11 | "laravel likes", 12 | "laravel rates", 13 | "laravel subscribes", 14 | "laravel subscribers", 15 | "laravel votes", 16 | "laravel follows", 17 | "laravel followers", 18 | "laravel favourties", 19 | "laravel bookmarks", 20 | "laravel", 21 | "php" 22 | ], 23 | "license": "MIT", 24 | "authors": [ 25 | { 26 | "name": "Moamen Eltouny (Raggi)", 27 | "email": "support@raggitech.com" 28 | } 29 | ], 30 | "require": { 31 | "php": ">=7.2", 32 | "laravel/framework": ">=6.0", 33 | "pharaonic/laravel-agents-detector": "^1.0.3", 34 | "pharaonic/laravel-translatable": "^2.0.0" 35 | }, 36 | "config": { 37 | "sort-packages": true 38 | }, 39 | "extra": { 40 | "laravel": { 41 | "providers": [ 42 | "Pharaonic\\Laravel\\Users\\UsersServiceProvider" 43 | ] 44 | } 45 | }, 46 | "autoload": { 47 | "psr-4": { 48 | "Pharaonic\\Laravel\\Users\\": "src" 49 | }, 50 | "files": ["src/helpers.php"] 51 | }, 52 | "minimum-stability": "dev", 53 | "prefer-stable": true 54 | } -------------------------------------------------------------------------------- /src/Traits/Actions/Comment/isCommentable.php: -------------------------------------------------------------------------------- 1 | comments()->delete(); 20 | } else { 21 | $model->comments()->forceDelete(); 22 | } 23 | }); 24 | } 25 | 26 | /** 27 | * Comment with a Model 28 | * 29 | * @param Authenticatable $commenter 30 | * @param string $comment 31 | * @return boolean 32 | */ 33 | public function commentBy(Authenticatable $commenter, string $comment) 34 | { 35 | return $this->comments()->make(['comment' => $comment])->commenter()->associate($commenter)->save(); 36 | } 37 | 38 | /** 39 | * Has Commented By Commenter 40 | * 41 | * @param Authenticatable $commenter 42 | * @return boolean 43 | */ 44 | public function commentedBy(Authenticatable $commenter) 45 | { 46 | return $this->comments()->where(['commenter_id' => $commenter->getKey(), 'commenter_type' => get_class($commenter)])->exists(); 47 | } 48 | 49 | /** 50 | * Comments List 51 | * 52 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 53 | */ 54 | public function comments() 55 | { 56 | return $this->morphMany(Comment::class, 'commentable'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Traits/Actions/Like/isLiker.php: -------------------------------------------------------------------------------- 1 | likes()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Like Model 24 | * 25 | * @param Model $likeable 26 | * @return boolean 27 | */ 28 | public function like(Model $likeable) 29 | { 30 | if ($this->liked($likeable)) 31 | return true; 32 | 33 | return $this->likes()->make()->likeable()->associate($likeable)->save(); 34 | } 35 | 36 | /** 37 | * Unlike Model 38 | * 39 | * @param Model $likeable 40 | * @return boolean 41 | */ 42 | public function unlike(Model $likeable) 43 | { 44 | if ($like = $this->likes()->where(['likeable_id' => $likeable->getKey(), 'likeable_type' => get_class($likeable)])->first()) 45 | return $like->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Liked By Liker 52 | * 53 | * @param Model $likeable 54 | * @return boolean 55 | */ 56 | public function liked(Model $likeable) 57 | { 58 | return $this->likes()->where(['likeable_id' => $likeable->getKey(), 'likeable_type' => get_class($likeable)])->exists(); 59 | } 60 | 61 | /** 62 | * liker List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function likes() 67 | { 68 | return $this->morphMany(Like::class, 'liker'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Like/isLikeable.php: -------------------------------------------------------------------------------- 1 | likes()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Like with a Model 24 | * 25 | * @param Authenticatable $liker 26 | * @return boolean 27 | */ 28 | public function likeBy(Authenticatable $liker) 29 | { 30 | if ($this->likedBy($liker)) 31 | return true; 32 | 33 | return $this->likes()->make()->liker()->associate($liker)->save(); 34 | } 35 | 36 | /** 37 | * Unlike with a Model 38 | * 39 | * @param Authenticatable $liker 40 | * @return boolean 41 | */ 42 | public function unLikeBy(Authenticatable $liker) 43 | { 44 | if ($like = $this->likes()->where(['liker_id' => $liker->getKey(), 'liker_type' => get_class($liker)])->first()) 45 | return $like->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Liked By Liker 52 | * 53 | * @param Authenticatable $liker 54 | * @return boolean 55 | */ 56 | public function likedBy(Authenticatable $liker) 57 | { 58 | return $this->likes()->where(['liker_id' => $liker->getKey(), 'liker_type' => get_class($liker)])->exists(); 59 | } 60 | 61 | /** 62 | * Likes List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function likes() 67 | { 68 | return $this->morphMany(Like::class, 'likeable'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Follow/isFollower.php: -------------------------------------------------------------------------------- 1 | follows()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Follow Model 24 | * 25 | * @param Model $followable 26 | * @return boolean 27 | */ 28 | public function follow(Model $followable) 29 | { 30 | if ($this->followed($followable)) 31 | return true; 32 | 33 | return $this->follows()->make()->followable()->associate($followable)->save(); 34 | } 35 | 36 | /** 37 | * Unfollow Model 38 | * 39 | * @param Model $followable 40 | * @return boolean 41 | */ 42 | public function unfollow(Model $followable) 43 | { 44 | if ($follow = $this->follows()->where(['followable_id' => $followable->getKey(), 'followable_type' => get_class($followable)])->first()) 45 | return $follow->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Followd By follower 52 | * 53 | * @param Model $followable 54 | * @return boolean 55 | */ 56 | public function followed(Model $followable) 57 | { 58 | return $this->follows()->where(['followable_id' => $followable->getKey(), 'followable_type' => get_class($followable)])->exists(); 59 | } 60 | 61 | /** 62 | * Follows List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function follows() 67 | { 68 | return $this->morphMany(Follow::class, 'follower'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Favourite/isFavorer.php: -------------------------------------------------------------------------------- 1 | favourites()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Favourite Model 24 | * 25 | * @param Model $favourable 26 | * @return boolean 27 | */ 28 | public function favourite(Model $favourable) 29 | { 30 | if ($this->favoured($favourable)) 31 | return true; 32 | 33 | return $this->favourites()->make()->favourable()->associate($favourable)->save(); 34 | } 35 | 36 | /** 37 | * Unfavourite Model 38 | * 39 | * @param Model $favourable 40 | * @return boolean 41 | */ 42 | public function unfavourite(Model $favourable) 43 | { 44 | if ($favourite = $this->favourites()->where(['favourable_id' => $favourable->getKey(), 'favourable_type' => get_class($favourable)])->first()) 45 | return $favourite->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Favoured By Favour 52 | * 53 | * @param Model $favourable 54 | * @return boolean 55 | */ 56 | public function favoured(Model $favourable) 57 | { 58 | return $this->favourites()->where(['favourable_id' => $favourable->getKey(), 'favourable_type' => get_class($favourable)])->exists(); 59 | } 60 | 61 | /** 62 | * Favourites List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function favourites() 67 | { 68 | return $this->morphMany(Favourite::class, 'favorer'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Follow/isFollowable.php: -------------------------------------------------------------------------------- 1 | follows()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Follow with a Model 24 | * 25 | * @param Authenticatable follower 26 | * @return boolean 27 | */ 28 | public function followBy(Authenticatable $follower) 29 | { 30 | if ($this->followedBy($follower)) 31 | return true; 32 | 33 | return $this->follows()->make()->follower()->associate($follower)->save(); 34 | } 35 | 36 | /** 37 | * Un-follow with a Model 38 | * 39 | * @param Authenticatable follower 40 | * @return boolean 41 | */ 42 | public function unFollowBy(Authenticatable $follower) 43 | { 44 | if ($follow = $this->follows()->where(['follower_id' => $follower->getKey(), 'follower_type' => get_class($follower)])->first()) 45 | return $follow->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Followed By Follower 52 | * 53 | * @param Authenticatable follower 54 | * @return boolean 55 | */ 56 | public function followedBy(Authenticatable $follower) 57 | { 58 | return $this->follows()->where(['follower_id' => $follower->getKey(), 'follower_type' => get_class($follower)])->exists(); 59 | } 60 | 61 | /** 62 | * Follows List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function follows() 67 | { 68 | return $this->morphMany(Follow::class, 'followable'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Favourite/isFavourable.php: -------------------------------------------------------------------------------- 1 | favourites()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Favourite with a Model 24 | * 25 | * @param Authenticatable $favorer 26 | * @return boolean 27 | */ 28 | public function favouriteBy(Authenticatable $favorer) 29 | { 30 | if ($this->favouredBy($favorer)) 31 | return true; 32 | 33 | return $this->favourites()->make()->favorer()->associate($favorer)->save(); 34 | } 35 | 36 | /** 37 | * Unfavourite with a Model 38 | * 39 | * @param Authenticatable $favorer 40 | * @return boolean 41 | */ 42 | public function unFavouriteBy(Authenticatable $favorer) 43 | { 44 | if ($favourite = $this->favourites()->where(['favorer_id' => $favorer->getKey(), 'favorer_type' => get_class($favorer)])->first()) 45 | return $favourite->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Favoured By favour 52 | * 53 | * @param Authenticatable $favorer 54 | * @return boolean 55 | */ 56 | public function favouredBy(Authenticatable $favorer) 57 | { 58 | return $this->favourites()->where(['favorer_id' => $favorer->getKey(), 'favorer_type' => get_class($favorer)])->exists(); 59 | } 60 | 61 | /** 62 | * Favourites List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function favourites() 67 | { 68 | return $this->morphMany(Favourite::class, 'favourable'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Subscribe/isSubscriber.php: -------------------------------------------------------------------------------- 1 | subscriptions()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Subscribe Model 24 | * 25 | * @param Model $subscribable 26 | * @return boolean 27 | */ 28 | public function subscribe(Model $subscribable) 29 | { 30 | if ($this->subscribed($subscribable)) 31 | return true; 32 | 33 | return $this->subscriptions()->make()->subscribable()->associate($subscribable)->save(); 34 | } 35 | 36 | /** 37 | * Unsubscribe Model 38 | * 39 | * @param Model $subscribable 40 | * @return boolean 41 | */ 42 | public function unsubscribe(Model $subscribable) 43 | { 44 | if ($subscription = $this->subscriptions()->where(['subscribable_id' => $subscribable->getKey(), 'subscribable_type' => get_class($subscribable)])->first()) 45 | return $subscription->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Subscribed By Subscriber 52 | * 53 | * @param Model $subscribable 54 | * @return boolean 55 | */ 56 | public function subscribed(Model $subscribable) 57 | { 58 | return $this->subscriptions()->where(['subscribable_id' => $subscribable->getKey(), 'subscribable_type' => get_class($subscribable)])->exists(); 59 | } 60 | 61 | /** 62 | * Subscriptions List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function subscriptions() 67 | { 68 | return $this->morphMany(Subscribe::class, 'subscriber'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Traits/Actions/Subscribe/isSubscribable.php: -------------------------------------------------------------------------------- 1 | subscriptions()->delete(); 19 | }); 20 | } 21 | 22 | /** 23 | * Subscribe with a Model 24 | * 25 | * @param Authenticatable $subscriber 26 | * @return boolean 27 | */ 28 | public function subscribeBy(Authenticatable $subscriber) 29 | { 30 | if ($this->subscribedBy($subscriber)) 31 | return true; 32 | 33 | return $this->subscriptions()->make()->subscriber()->associate($subscriber)->save(); 34 | } 35 | 36 | /** 37 | * Unsubscribe with a Model 38 | * 39 | * @param Authenticatable $subscriber 40 | * @return boolean 41 | */ 42 | public function unSubscribeBy(Authenticatable $subscriber) 43 | { 44 | if ($subscription = $this->subscriptions()->where(['subscriber_id' => $subscriber->getKey(), 'subscriber_type' => get_class($subscriber)])->first()) 45 | return $subscription->delete(); 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * Has Subscribed By Subscriber 52 | * 53 | * @param Authenticatable $subscriber 54 | * @return boolean 55 | */ 56 | public function subscribedBy(Authenticatable $subscriber) 57 | { 58 | return $this->subscriptions()->where(['subscriber_id' => $subscriber->getKey(), 'subscriber_type' => get_class($subscriber)])->exists(); 59 | } 60 | 61 | /** 62 | * Subscriptions List 63 | * 64 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 65 | */ 66 | public function subscriptions() 67 | { 68 | return $this->morphMany(Subscribe::class, 'subscribable'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
LARAVEL USERS16 | 17 |
18 | Roles & Permissions Devices
19 | Password Hashing Password History
20 |
23 | Likes Followers Subscriptions
24 | Reviews Rates Favourites Bookmarks
25 |