Back to Course |
Filament Adminpanel for Booking.com API Project

Manage Facilities with their Categories

In this lesson, we will add Facility Category to the Facilities navigation group and will use Relation Manager to show and add Facility to the Facility category.


First, let's create a Facility Category resource and add it to the Facility group, and let's add a form and a table. Facility Group will have only a name field.

php artisan make:filament-resource FacilityCategory

app/Filament/Resources/FacilityCategoryResource.php:

class FacilityCategoryResource extends Resource
{
protected static ?string $model = FacilityCategory::class;
 
protected static ?string $navigationIcon = 'heroicon-o-collection';
 
protected static ?string $navigationGroup = 'Facilities';
 
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required(),
]);
}
 
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
// ...
}

facility categories

Next, let's create a relation manager and add it to the Facility Category resource.

php artisan make:filament-relation-manager FacilityCategory facilities name

app/Filament/Resources/FacilityCategoryResource.php:

class FacilityCategoryResource extends Resource
{
// ...
public static function getRelations(): array
{
return [
RelationManagers\FacilitiesRelationManager::class,
];
}
// ...
}

Now, because facilities don't have any other fields besides name, and in relation manager we defined name as an attribute to identify Facility Category, we don't need to add any additional fields to the form or table.

facilities