*/ use HasFactory, Notifiable, SoftDeletes; protected $fillable = [ 'name', 'email', 'phone', 'role', 'is_active', 'created_by', 'password', 'failed_login_count', 'last_failed_login_at', 'last_login_at', ]; protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'is_active' => 'boolean', 'last_failed_login_at' => 'datetime', 'last_login_at' => 'datetime', ]; } public function permissions(): BelongsToMany { return $this->belongsToMany(Permission::class, 'role_permissions', 'role', 'permission_id', 'role', 'id'); } public function hasPermission(string $code): bool { if ($this->role === 'admin') { return true; } return Permission::query() ->where('code', $code) ->whereExists(function ($query): void { $query->selectRaw('1') ->from('role_permissions') ->whereColumn('role_permissions.permission_id', 'permissions.id') ->where('role_permissions.role', $this->role); }) ->exists(); } public function getJWTIdentifier(): mixed { return $this->getKey(); } public function getJWTCustomClaims(): array { return [ 'role' => $this->role, 'name' => $this->name, ]; } }