F
Filament10mo ago
tjodalv

How to switch eloquent record context for table action

I have a table action that when clicked open infolist. But I want to change the eloquent record context for that infolist. I've tried with mountUsing but with no luck:
\Filament\Tables\Actions\Action::make('my-action')
->mountUsing(function ($action, App\Models\SomeModel $record) {
$otherModel = App\Models\OtherModel::find(1);
// Here I am trying to switch record context for my action infolist but unfortunately it doesn't work. Infolist still gets data from SomeModel
$action->record($otherModel);
})
->infolist([
TextEntry::make('name')
->label('This should be populated from OtherModel')
])
\Filament\Tables\Actions\Action::make('my-action')
->mountUsing(function ($action, App\Models\SomeModel $record) {
$otherModel = App\Models\OtherModel::find(1);
// Here I am trying to switch record context for my action infolist but unfortunately it doesn't work. Infolist still gets data from SomeModel
$action->record($otherModel);
})
->infolist([
TextEntry::make('name')
->label('This should be populated from OtherModel')
])
If I use form then I can bind different record in mountUsing by calling $form->model($otherModel); and then $form->fill($otherModel->toArray());
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server