*/ use HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'avatar', 'bio', 'website', 'twitter', 'github', 'linkedin', ]; /** * The attributes that should be hidden for serialization. * * @var list */ 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', ]; } /** * Get the roles that belong to the user. */ public function roles(): BelongsToMany { return $this->belongsToMany(Role::class); } /** * Check if user has a specific role. */ public function hasRole(string $role): bool { return $this->roles()->where('slug', $role)->exists(); } /** * Check if user has any of the given roles. */ public function hasAnyRole(array $roles): bool { return $this->roles()->whereIn('slug', $roles)->exists(); } /** * Check if user is an admin. */ public function isAdmin(): bool { return $this->hasRole('admin'); } /** * Check if user is a moderator. */ public function isModerator(): bool { return $this->hasRole('moderator'); } /** * Check if user is a regular user. */ public function isUser(): bool { return $this->hasRole('user'); } /** * Get the user's avatar URL. */ public function getAvatarUrlAttribute(): ?string { if ($this->avatar) { return asset('storage/avatars/' . $this->avatar); } return null; } }