In this lesson, let's show the main data of Bookings
. In this resource, instead of the Delete
action, we will call it Cancel
.
As always, first, the resource.
php artisan make:filament-resource BookingResource
Now let's add a form and a table.
app/Filament/Resources/BookingResource.php:
class BookingResource extends Resource{ protected static ?string $model = Booking::class; protected static ?string $navigationIcon = 'heroicon-o-collection'; public static function form(Form $form): Form { return $form ->schema([ Forms\Components\Select::make('apartment_id') ->required() ->searchable() ->relationship('apartment', 'name'), Forms\Components\Select::make('user_id') ->required() ->searchable() ->relationship('user', 'name'), Forms\Components\DatePicker::make('start_date') ->required(), Forms\Components\DatePicker::make('end_date') ->required(), Forms\Components\TextInput::make('guests_adults') ->integer() ->required() ->minValue(0), Forms\Components\TextInput::make('guests_children') ->integer() ->required() ->minValue(0), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('apartment.name'), Tables\Columns\TextColumn::make('start_date') ->date(), Tables\Columns\TextColumn::make('end_date') ->date(), Tables\Columns\TextColumn::make('total_price') ->money(), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), ]); } // ...}
To use the form, we need to add a user
relation to the Booking
model.
use Illuminate\Database\Eloquent\Relations\BelongsTo; class Booking extends Model{ // ... public function user(): BelongsTo { return $this->belongsTo(User::class); }}
Next, let's add a Delete action but give it a label of Cancel
. And for the bulk actions, we will also change the label to Cancel
.
app/Filmanet/Resoources/BookingResource.php:
class BookingResource extends Resource{ // ... public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('apartment.name'), Tables\Columns\TextColumn::make('start_date') ->date(), Tables\Columns\TextColumn::make('end_date') ->date(), Tables\Columns\TextColumn::make('total_price') ->money(), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make()v ->label('Cancel'), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make() ->label('Cancel'), ]); } // ...}
Now in the edit page, the delete action is still named Delete
. Let's add a label.
app/Filament/Resources/BookingResource/EditBooking.php:
class EditBooking extends EditRecord{ protected static string $resource = BookingResource::class; protected function getActions(): array { return [ Actions\DeleteAction::make() ->label('Cancel'), ]; }}