This project demonstrates multiple panels in one Filament application: one for hotel management, and another for search and book hotel rooms.
In this Filament Example project, we have two panels:
When a user registers to any panel, they are automatically assigned a role based on the panel. It is done in Eloquent Events closures method in the User Model.
protected static function booted(): void{ static::created(function (User $user) { if (filament()->getCurrentOrDefaultPanel()->getId() === 'hotel') { $user->assignRole('hotels'); } if (filament()->getCurrentOrDefaultPanel()->getId() === 'booking') { $user->assignRole('customers'); } });}
According to the role, the user gets access to a panel.
public function canAccessPanel(Panel $panel): bool{ if ($panel->getId() === 'hotel' && $this->hasRole('hotels')) { return true; } if ($panel->getId() === 'booking' && $this->hasRole('customers')) { return true; } return false;}
In the hotel panel, we have a custom page, MyHotel
, where users can manage information about their hotel. It is a HasOne
relation to the Hotel Model.
public function hotel(): HasOne{ return $this->hasOne(Hotel::class);}
Next, in this example, we will: