F
Filament7mo 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]))),
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);
});
->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?
1 Reply
toeknee
toeknee7mo ago
So if you look at the default search query you can see how it works. So return the url and add the table search to it i.e. ?tableSortColumn=created_at&tableSortDirection=desc&tableSearch=Tony
Want results from more Discord servers?
Add your server