Passing the current record to an Action

Hi. I'm new to Filament but think it is an amazing piece of software. I'm struggling with something that I think "should" be possible but I've just hit a wall. I have a Nursery Resource that defines an action select
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),

])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('select')
->action('select')
])
->bulkActions([
//
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),

])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('select')
->action('select')
])
->bulkActions([
//
]);
}
When I hit 'select' is does indeed call the correct funtion in ListNuerseries.php BUT I cannot for the life of me see how to pass the current record. I'm sure I'm doing something daft but any help would be appreciated.
Solution:
To answer my own question. It turned out to be quite logical (as most things seem to be with Filament).
Jump to solution
4 Replies
cheesegrits
cheesegrits14mo ago
As per the doc, use a fn() closure and pass in $record. You can use your model type, but can't change the injected parameter name, it has to be $record. https://filamentphp.com/docs/3.x/tables/actions/#row-actions
ShortlyPortly1964
ShortlyPortly1964OP14mo ago
Hi @Hugh Messenger - thank you for this. I did see this but then couldn't work out how to actually call the livewire method (in my case 'select'). I'm still new to Filament/Livewire so would you be able to show me an example - many thanks. Hi again - don't worry about I actually worked it out. I'll post my solution shortly :-).
Solution
ShortlyPortly1964
To answer my own question. It turned out to be quite logical (as most things seem to be with Filament).
ShortlyPortly1964
ShortlyPortly1964OP14mo ago
Tables\Actions\Action::make('select') ->action(function (Component $livewire, Model $record) { $livewire->select($record);
Want results from more Discord servers?
Add your server