*/ use HasFactory, Notifiable; /** * The table associated with the model. * * @var string */ protected $table = 'users'; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = 'id'; /** * Indicates if the model's ID is auto-incrementing. * * @var bool */ public $incrementing = true; /** * The data type of the primary key ID. * * @var string */ protected $keyType = 'int'; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'id', 'user_id', 'username', 'email', 'password', 'password_hash', 'full_name', 'role', 'phone', 'department', 'is_active', 'remember_token', 'last_login', 'login_count', 'deleted_at', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password_hash', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'is_active' => 'boolean', ]; } public function canAccessPanel(?Panel $panel): bool { // 只有激活的用户才能访问面板 return $this->is_active === true; } /** * Get the password for authentication. */ public function getAuthPassword(): string { return (string) $this->password_hash; } /** * Get the password attribute (for compatibility). */ public function getPasswordAttribute(): string { return $this->password_hash; } /** * Set the password attribute (for compatibility). */ public function setPasswordAttribute(string $value): void { $this->attributes['password_hash'] = $value; } /** * Get the name to display for the user in Filament. * This fixes the TypeError where getUserName() expected string but got null. */ public function getFilamentName(): string { return $this->full_name ?: $this->username ?: $this->email ?: 'Unknown User'; } }