FilamentF
Filament2y ago
pace

How to use a parameter to change a resource table query?

I am working with : FolderResource and AccessLinkResource.
An AccessLink belongs to an Folder. And Folderhave many AccessLinks.

I am trying to create a AccessLinkResource which show and create the records using the folder_id.

The first step is filter the records of AccessLinkResource table using the folder_id.
To do that, i created a button in FolderResource:

 Tables\Actions\ViewAction::make('accessLink'))
                    ->url(fn(Folder $record): string => url(AccessLinkResource::getUrl('index', ['folder_id' => $record->id]))),


And i used the modifyQueryUsing in AccessLinktable:

 ->modifyQueryUsing(function (Builder $query) {
                $folderId = Request::query('folder_id');
                $query->where('folder_id', $folderId);
            });

It works in the first load of the page, but when use the pagination return no records.
What it is the correct way to handle this? How can I use the $folder_id param in a static method?
Was this page helpful?