*/ use HasFactory, Notifiable, HasRoles, HasApiTokens; public function canAccessPanel(Panel $panel): bool { return $this->hasRole(['admin', 'editor']); } /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'legacy_md5', 'url', 'logincount', 'loginip', 'regip', 'logintime', 'lastpost_at', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', 'legacy_md5', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'logintime' => 'datetime', 'lastpost_at' => 'datetime', ]; } public function posts(): HasMany { return $this->hasMany(Post::class); } public function comments(): HasMany { return $this->hasMany(Comment::class); } /** * 验证登录:优先新密码哈希,兼容 sablog 老 MD5 密码。 */ public function verifyPassword(string $plain): bool { if ($this->password && Hash::check($plain, $this->password)) { return true; } if ($this->legacy_md5 && md5($plain) === strtolower($this->legacy_md5)) { // 登录成功后自动升级为现代哈希 $this->password = Hash::make($plain); $this->legacy_md5 = null; $this->save(); return true; } return false; } public function isAdmin(): bool { return $this->hasRole('admin'); } }