Infolist - send data to Action

Hi - I need some help on creating an Infolist-Action. As you can see on the screenshot, I have a Chekpoint that has multiple tags. When a user clicks on the red button, the tag is beeing removed from the checkpoint. Right now I have this code:
Section::make('Tags')
->columns(3)
->schema(function (){
$schema = [];
foreach ($this->record->tags->sortBy('tagname') as $tag){
$schema[] = TextEntry::make('tag_'.$tag->id)
->label(false)
->state($tag->tagname)
->suffixAction(
Action::make('remove_tag')
->icon('heroicon-o-x-mark')
->button()
->color('danger')
->label(false)
->tooltip('Remove Tag')
->action(function (Tag $tag, $record){
dd($record, $tag);
})
);
}
return $schema;
})
Section::make('Tags')
->columns(3)
->schema(function (){
$schema = [];
foreach ($this->record->tags->sortBy('tagname') as $tag){
$schema[] = TextEntry::make('tag_'.$tag->id)
->label(false)
->state($tag->tagname)
->suffixAction(
Action::make('remove_tag')
->icon('heroicon-o-x-mark')
->button()
->color('danger')
->label(false)
->tooltip('Remove Tag')
->action(function (Tag $tag, $record){
dd($record, $tag);
})
);
}
return $schema;
})
But $tagcomes in as an empty model. If I use $data instead of $tag, I get an empty array. I already tried to use ->formFill(['tag_id' => $tag->id]), but to no avail. How do I send the tag-ID to the action? The relationship between Checkpoint -> Tag is BelongsToMany. Thanks.
No description
Solution:
Try passing it to the function via use ($tag). Filament doesn’t know about your tag so it can’t inject it as an argument
Jump to solution
5 Replies
Solution
Dennis Koch
Dennis Koch7mo ago
Try passing it to the function via use ($tag). Filament doesn’t know about your tag so it can’t inject it as an argument
Husky110
Husky1107mo ago
Worked! Thanks Dennis. 🙂
Husky110
Husky1107mo ago
Do you also have an idea on how to fix the weird looking buttons? As soon as I set label(false) but keep an icon, the icon is not centered inside the button. I ain't sure if I do something wrong or if Filament has trouble creating "icon-only"-buttons.
No description
ChesterS
ChesterS7mo ago
try iconButton() instead of button()
Husky110
Husky1107mo ago
Then it looks like this - I would prefer to have just the icon as label you know. 🙂
No description
Want results from more Discord servers?
Add your server
More Posts