how to pass parent record to relation manager bulkaction

I have this bulk action in a relationmanager: I want to pass, alongside the $records, the parent record. how can I do that?
BulkAction::make('Marquer comme réussi')
->color('info')
->deselectRecordsAfterCompletion()
->visible()
->action(function ($records) {
foreach ($records as $record) {
$record->update(['cert_code' => bin2hex(random_bytes(4))]);
}
})
BulkAction::make('Marquer comme réussi')
->color('info')
->deselectRecordsAfterCompletion()
->visible()
->action(function ($records) {
foreach ($records as $record) {
$record->update(['cert_code' => bin2hex(random_bytes(4))]);
}
})
3 Replies
dotdotdot
dotdotdotOP2mo ago
my goal initially was the make the action hidden if a certain attribute on the parent is set, but I couldn't do that with the ->hidden since it doesn't accept callbacks so what I am going to do instead is show an error notification if that attribute is set on the parent, and to do that I need to pass the parent record
dotdotdot
dotdotdotOP2mo ago
that works, thanks!

Did you find this page helpful?