Livewire Component within tabs in Resource View

Hi I have an Infolist Builder, and within it, I ahve created some tabs. Now, I've worked out how to get a Livewire Component to render some content to one of the tabs, but what I would like is for that Livewire Component to display related objects.
I am also able to do that, but rather than showing objects related to the Resource I'm viewing, it shows ALL (in my component I have $table->query(Related::query()) so that doesn't really surprise me that it does that. What I would like to know is how I can get the parent Resource model/ID in the Component to be able to alter the query method to only return related models
Solution:
perhaps:
Livewire::make(ListVIPs::class, ['customer' => $infolist->getRecord()])
Livewire::make(ListVIPs::class, ['customer' => $infolist->getRecord()])
then in ListVIPs class, define customer public property to use it in ur query or elsewhere....
Jump to solution
4 Replies
KeyMe
KeyMe3mo ago
@sdousley can u show the code where u call/render the livewire component?
sdousley
sdousley3mo ago
Sorry, yes, I should have included that, so in App\Filamenet\Resources\CustomerResource I have the infolist method, and in that, i have:
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
InfolistsComponents\Tabs::make('Tabs')
->columnSpanFull()
->tabs([
// other tabs InfolistsComponents\Tabs\Tab::make('VIPs')
->columns(1)
->schema([
InfolistsComponents\Livewire::make(ListVIPs::class)
]),
]);
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
InfolistsComponents\Tabs::make('Tabs')
->columnSpanFull()
->tabs([
// other tabs InfolistsComponents\Tabs\Tab::make('VIPs')
->columns(1)
->schema([
InfolistsComponents\Livewire::make(ListVIPs::class)
]),
]);
}
ListVIPs is the Livewire component, which has the table method to display the results, I'm guessing I just need some way to filter in the ->query() method, but that's where I'm unsure
public function table(Table $table): Table
{
return $table
->query(VIP::query())
->columns([
Tables\Columns\TextColumn::make('id')
->searchable()->label('ID'),
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->actions([
//
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
//
]),
]);
}
public function table(Table $table): Table
{
return $table
->query(VIP::query())
->columns([
Tables\Columns\TextColumn::make('id')
->searchable()->label('ID'),
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->actions([
//
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
//
]),
]);
}
Or if there's a better way of doing this, I'm more than open to other suggestions
Solution
KeyMe
KeyMe3mo ago
perhaps:
Livewire::make(ListVIPs::class, ['customer' => $infolist->getRecord()])
Livewire::make(ListVIPs::class, ['customer' => $infolist->getRecord()])
then in ListVIPs class, define customer public property to use it in ur query or elsewhere. refer to this: https://filamentphp.com/docs/3.x/infolists/advanced#passing-parameters-to-a-livewire-component
sdousley
sdousley3mo ago
OK yes, that gets the customer into the Livewire Component, it was the $infolist->getRecord() that I was missing. I have, however, since found that by adding the RelationsManagers for models and defining the code in the view customer blade template to show the relations, that actually works as I was trying to make work with the tabs. Plus being more natively filament, is probably better Either way, I will mark the above as the solution, as it actually answered my question thanks @KeyMe