Closed nickw-lr closed 1 year ago
@nickw-lr why not edit directly in resource file?
PostResource.php
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
@faizananwerali This was just a demonstration of the issue, when following the instructions from the docs.
I have an instance in my actual project where I need to filter the list of posts that have child posts. So I have a self related relation manager for the children. I need the list page for the resource to be scoped to only show posts without a parent, so that I can sort their order with an action on the list page.
If I scope the resource itself, then I can no longer use the view page from the main resource on the child posts in the relation manager (because they are out of the global scope).
I think this was fixed a couple of weeks ago in a different PR. Please test on the latest version, if it still doesn't work then I will reopen this issue, but I'm pretty sure it should be ok now 👍
Hi @danharrin, I've updated my demo repo to filament v3.77 and the issue still appears to be there.
Is there an error?
Nothing in the Laravel log file or console log. Just an "empty" posts page.
ListRecords::table()
is going to override the resource table()
. You just need to define modifyQueryUsing()
on the resource table, or move the rest of the resource table code into the ListRecords
page. So the table configuration is all in one place.
This is unrelated to the query, if you make query modifications in the resource table()
then they will only apply to the table. Only if you use getEloquentQuery()
will it apply to the other pages too.
That has done the trick, thanks for that @danharrin !
The docs need to be updated - they're wrong: https://filamentphp.com/docs/3.x/panels/resources/listing-records#customizing-the-table-eloquent-query
It should be:
public function table(Table $table): Table
{
return parent::table($table)
->modifyQueryUsing(fn(Builder $query) => $query->withoutGlobalScopes());
}
Actually, you should just to this in the resource table()
method
I've updated the docs to reflect that
Package
filament/filament
Package Version
v3.0.56
Laravel Version
v10.24.0
Livewire Version
v3.0.5
PHP Version
PHP 8.2.4
Problem description
Referencing #8549
"If you update the list resource query using table() - your list view will no longer render."
The issue was closed because no repo was provided. I have created a repo to demonstrate the problem.
Expected behavior
The table view should generate.
Steps to reproduce
Run steps from the provided repo's readme.
Reproduction repository
https://github.com/nickw-lr/filament-bugreport/tree/main
Relevant log output
No response