Unique filters for same table in multiple locations

Hi all, I have a resource, lets say Product, which has a reasonably developed table, with a few columns with added descriptions, badge columns, filters etc.. I have a second resource Order, and a single order may have multiple Products, so I created a RelationManager to list associated products on the Order resource page. All works fine. My only problem is that when viewing Products on an Order page, any filters which might have been applied when viewing Products on the Product page, are applied to the view on the Order page. So essentially my question is, is there away of applying filters uniquely, depending on where the table is displayed? :wq
4 Replies
LeandroFerreira
I think you can use the same table ProductResource in your ProductsRelationManager class like ProductsRelationManager.php
public function table(Table $table): Table
{
return ProductResource::table($table)
->recordTitleAttribute('name') //set your titleAttribute
//override the methods if you need as ->columns([...]), ->actions([...])
->headerActions([
Tables\Actions\CreateAction::make(),
]);
}
public function table(Table $table): Table
{
return ProductResource::table($table)
->recordTitleAttribute('name') //set your titleAttribute
//override the methods if you need as ->columns([...]), ->actions([...])
->headerActions([
Tables\Actions\CreateAction::make(),
]);
}
potz1024
potz1024OP3d ago
Thanks @LeandroFerreira. Apologies, I realised I wasn't clear in my question. Yes, I am using the same table, by calling the static table method of the Product resource from within my relation manager.
And I think this is part of my issue, because I'm using the same table definition, I have the same filters. But if filters are set on the table on my Product page, then the same filters will be set in the relation on my Orders page. Ideally I don't want these filters linked.
E.g. let's say I have an 'available' toggle filter on my Product table, and that toggle has been set to true on the Products page, then when you navigate to the orders page, that same filter will be applied. :wq
LeandroFerreira
maybe you could inject $livewire to add conditions to the filter fields like
Filter::make('xx')
->toggle()
->default(fn ($livewire): bool => ! str($livewire->getName())->contains('relation-manager'))
Filter::make('xx')
->toggle()
->default(fn ($livewire): bool => ! str($livewire->getName())->contains('relation-manager'))
potz1024
potz1024OP3d ago
Thanks @LeandroFerreira for the pointer, I'll investigate that.

Did you find this page helpful?