Multiple Resources with different table query but tables appearance is not different

In my list I overridden getTableQuery() based on path <?php namespace App\Filament\Resources\BiciklResource\Pages; use App\Filament\Resources\BiciklResource; use App\Filament\Resources\BiciklAktivniResource; use App\Filament\Resources\BiciklArhivaResource; use App\Models\Bicikl; use Filament\Pages\Actions; use Filament\Resources\Pages\ListRecords; use Illuminate\Database\Eloquent\Builder; class ListBicikls extends ListRecords { protected static string $resource = BiciklResource::class; protected function getActions(): array { return [ Actions\CreateAction::make(), ]; } protected function getTableRecordsPerPageSelectOptions(): array { return [12, 24, 48, 96, -1]; } protected function getTableQuery(): Builder { $path = request()->getPathInfo(); if ($path === '/admin/bicikli-aktivni') { return parent::getTableQuery()->where('pCena', null); } else if ( $path === '/admin/bicikli-arhiva' ) { return parent::getTableQuery()->whereNotNull('pCena'); } else { return parent::getTableQuery()->withoutGlobalScopes(); } } } But, even I changed tables in my Resources, they all look like one in BiciklResource. That's probably becuase of this line protected static string $resource = BiciklResource::class; Can I set this conditionally too or there is another way?
17 Replies
Filament
Filament2y ago
Please read the #✅┊rules about how to format your code properly.
Dennis Koch
Dennis Koch2y ago
Why aren't you creating separate Resources if you want separate table schema anyway? Or if it's only the table: Create separate ListPages with their own URL, register them on the resources getPages() (before the view and edit route) and define a custom table schema and query on them.
Štakor
ŠtakorOP2y ago
I want to achieve this, what is the best approach?
Štakor
ŠtakorOP2y ago
I created separate ListPages for active and archive with their own getTableQuery() , registered in getPages() and navigation items. Everything is wokring fine. I tried to conditionally return tables in my table function based on path but as soon as I try to use pagination tables dissapear. Can you please explain to me the last part you said: Define a custom table schema and query on them ?
Dennis Koch
Dennis Koch2y ago
Pretty much what you did. Define getTableQuery and getTableSchema on separate ListPages
Štakor
ŠtakorOP2y ago
I can't find getTableSchema anywhere in documentation Ok I used getTableColumns to define table. Did you mean that?
toeknee
toeknee2y ago
More than likely 🙂
Štakor
ŠtakorOP2y ago
I figured out everything 😄 Thank you!
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
toeknee
toeknee2y ago
Please provide the code, usually that's because you have defined an action which finishes it's self without doing anyhting.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
toeknee
toeknee2y ago
You need to provide more detail. Thats just a tableQuery not an action.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
toeknee
toeknee2y ago
Ok You probably need to update your forUser() method if it's failing. But otherwise wher eis fine you can also do:
return Product::where('users_id', auth()->id);
return Product::where('users_id', auth()->id);
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
toeknee
toeknee2y ago
Why are you doing the TableQuery? Why not just define the model in the resource? Have default policies enabled so they can only access / view their own
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server