Ali Safi
Ali Safi

Reputation: 11

How to make deep nest resources in Laravel filament

Material Selection > Quotation > Addendums

Thanks all

I can do that by making custom livewire pages but it would be great if there is any workaround this

Upvotes: 1

Views: 4191

Answers (1)

Dave
Dave

Reputation: 908

Yes, I struggled with this also, what you do is create the separate resources as normal.

Then inside the first resource, you can place a link inside the actions, table method:

->actions([
    Action::make('quotations')->url(fn ($record): string => url('admin/materials/quotations/'.$record->id)),
    Tables\Actions\EditAction::make(),
])

Next if you want the quotation to be hidden from the sidarbar

protected static bool $shouldRegisterNavigation = false;

specify the slug

protected static ?string $slug = 'materials/quotations';

In order to only load the related records:

public static function getEloquentQuery(): Builder
{
    return parent::getEloquentQuery()->where('material_id', request('record'));
}

Also the routes need to be updated

public static function getPages(): array
{
    return [
        'index'           => ListQuotations::route('/'),
        'edit'            => EditQuotation::route('/{record}/edit'),
        'quotations'         => ListQuotations::route('/{record}'),
        'quotations.create'  => CreateQuotation::route('/{record}/create'),
    ];
}

you will need to do these steps for each resource you want to link.

Here's a demo using courses, modules, units resources https://github.com/dcblogdev/filament-courses-demo/tree/main/app/Filament/Resources

Upvotes: 3

Related Questions