*/ protected $dates = ['deleted_at']; protected $fillable = [ 'username', 'first_name', 'last_name', 'phone', 'uid', 'email', 'password', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; public function groups() { return $this->belongsToMany(Group::class); } public function permissions() { // Get the permission IDs through the user's groups and roles $groupIds = $this->groups()->pluck('groups.id'); $roleIds = GroupRole::whereIn('group_id', $groupIds)->pluck('role_id'); $permissionIds = PermissionRole::whereIn('role_id', $roleIds)->pluck('permission_id'); return Permission::whereIn('id', $permissionIds); } public function hasPermissions($permissionName) { return $this->permissions()->where('name', $permissionName)->exists(); } }