*/ use HasFactory; use HashableId; use HasProfilePhoto; use HasRoles; use Notifiable; use TwoFactorAuthenticatable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'is_active', 'first_name', 'last_name', 'display_name', 'username', 'email', 'phone', 'site_id', 'facility_id', 'profile_photo_path', 'timezone', 'last_seen_at', 'password', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'two_factor_recovery_codes', 'two_factor_secret', ]; /** * The accessors to append to the model's array form. * * @var array */ protected $appends = [ 'profile_photo_url', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'is_active' => 'bool', 'email_verified_at' => 'datetime', 'last_seen_at' => 'datetime', 'password' => 'hashed', ]; } public function scopeActive($query) { return $query->where('is_active', true); } public function isAdmin(): bool { return cache()->remember('user.is_admin:'.$this->id, 5 * 60, fn () => $this->hasRole(UserRole::Admin) ); } public function may(Permission|iterable|string $perm): bool { return $this->isAdmin() || $this->can($perm); } }