*/ use HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'username', 'email', 'password', 'role', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'role' => UserRole::class, ]; /** * Get purchases for the user (one-to-many) */ public function purchases(): HasMany { return $this->hasMany(Purchase::class, 'user_id'); } /** * Get event reservations for the user. */ public function eventReservations() { return $this->belongsToMany(Event::class, 'event_reservations') ->withPivot('number_of_guests', 'status') ->withTimestamps(); } /** * Check if the user has a specific role */ public function hasRole(UserRole $role): bool { return $this->role === $role; } /** * Check if the user is a winemaker */ public function isWinemaker(): bool { return $this->role === UserRole::WINEMAKER; } /** * Check if the user is a customer */ public function isCustomer(): bool { return $this->role === UserRole::CUSTOMER; } /** * Check if the user is an admin */ public function isAdmin(): bool { return $this->role === UserRole::ADMIN; } /** * Check if the user is an employee */ public function isEmployee(): bool { return $this->role === UserRole::EMPLOYEE; } }