How can I limit the query on just one page using getEloquentQuery()

Hi. I don't need all the columns of a resource for my list page. How can I create a select() that only applies to the list page?
Solution:
The proper method seems to be
->modifyQueryUsing(fn (Builder $query) => $query->select(['id', 'title']))
->modifyQueryUsing(fn (Builder $query) => $query->select(['id', 'title']))
...
Jump to solution
4 Replies
Dennis Koch
Dennis Koch5mo ago
There should be a ->query() method on the Table object.
$table->query(fn ($query) => $query->select(...))
$table->query(fn ($query) => $query->select(...))
Not sure whether Filament might apply it's own selection though.
BuddhaNature
BuddhaNature5mo ago
That generates this error: An attempt was made to evaluate a closure for [Filament\Tables\Table], but [$query] was unresolvable. I did a source dive and it seems like it should work. I can't find any references to that method in the Tab;e docs.
Solution
BuddhaNature
BuddhaNature5mo ago
The proper method seems to be
->modifyQueryUsing(fn (Builder $query) => $query->select(['id', 'title']))
->modifyQueryUsing(fn (Builder $query) => $query->select(['id', 'title']))
Dennis Koch
Dennis Koch5mo ago
Sure. Query sets the initial query. That's why you don't get it as an argument. My bad
Want results from more Discord servers?
Add your server
More Posts