Filament: Hotel Management and Booking Rooms

This project demonstrates multiple panels in one Filament application: one for hotel management, and another for search and book hotel rooms.

Untitled design (16)

Get the Source Code:

How it works

In this Filament Example project, we have two panels:

  • Hotel, for managing hotel with rooms.
  • Booking, for making a room booking.

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()->getCurrentPanel()->getId() === 'hotel') {
$user->assignRole('hotels');
}
if (filament()->getCurrentPanel()->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;
}

Hotel Panel

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);
}

The form is filled in the Livewire components mount() method. For the form, we use Filament Forms.

app/Filament/Hotel/Pages/MyHotel.php:

use Filament\Pages\Page;
use Filament\Forms\Form;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Concerns\InteractsWithForms;
 
class MyHotel extends Page implements HasForms
{
use InteractsWithForms;
 
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.hotel.pages.my-hotel';
public ?array $data = [];
 
public function mount(): void
{
$this->form->fill(auth()->user()->hotel?->attributesToArray());
}
 
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required(),
TextInput::make('address')
->required(),
Textarea::make('description')
->required(),
FileUpload::make('photo')
->image()
->required(),
Checkbox::make('is_published'),
])
->statePath('data');
}
}

To add actions to the form, we use...

The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 50 Premium Examples for $99 Only Project Examples for $59