| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Models;
- // use Illuminate\Contracts\Auth\MustVerifyEmail;
- use Filament\Models\Contracts\FilamentUser;
- use Filament\Models\Contracts\HasName;
- use Filament\Panel;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- class User extends Authenticatable implements FilamentUser, HasName
- {
- /** @use HasFactory<\Database\Factories\UserFactory> */
- 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<string>
- */
- protected $fillable = [
- 'id',
- 'user_id',
- 'username',
- 'email',
- 'password',
- 'full_name',
- 'role',
- 'phone',
- 'department',
- 'is_active',
- ];
- /**
- * The attributes that should be hidden for serialization.
- *
- * @var list<string>
- */
- protected $hidden = [
- 'password',
- ];
- /**
- * Get the attributes that should be cast.
- *
- * @return array<string, string>
- */
- protected function casts(): array
- {
- return [
- 'email_verified_at' => 'datetime',
- 'is_active' => 'boolean',
- ];
- }
- public function canAccessPanel(Panel $panel): bool
- {
- return true; // 所有用户都可以访问面板
- }
- /**
- * Get the password for authentication.
- */
- public function getAuthPassword(): string
- {
- return (string) ($this->password_hash ?? $this->password ?? '');
- }
- /**
- * 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';
- }
- }
|