F
Filament4mo ago
Søren

$record in action closure in Infolist RepeatableEntry references parent model

RepeatableEntry::make('bidders')
->schema([
TextEntry::make('document.id')
->suffixActions([
Action::make('detach')
->action(fn (Bidder $record) => $record->document()->disassociate()->saveOrFail()),
]),
]),
RepeatableEntry::make('bidders')
->schema([
TextEntry::make('document.id')
->suffixActions([
Action::make('detach')
->action(fn (Bidder $record) => $record->document()->disassociate()->saveOrFail()),
]),
]),
In Filament 3 - the $record here would be the model that is being repeated/iterated (in this case, a Bidder model). But in Filament 4 it's passing in the $record of the resource being viewed. Is this an intended change?
3 Replies
Lirux
Lirux4mo ago
I had this issue too. I'm not sure if it's intended or not. My work around was:
use Filament\Schemas\Components\Component;
...
->action(fn (Component $component) =>
...
$record = $component->getContainer()->model
use Filament\Schemas\Components\Component;
...
->action(fn (Component $component) =>
...
$record = $component->getContainer()->model
Søren
SørenOP4mo ago
Thanks @Lirux - that solution works for me. I think I'll leave the post be. If a Filament member will confirm it's not intended, then I'll make an issue on git.
Shavik
Shavik4w ago
Yea this was an unexpected change. Not getting access to the model being iterated on seems to be a big problem. I couldn't find this documented anywhere. Anyone found a better solution than this?

Did you find this page helpful?