How to Access Selected Records in a BulkAction::visible() in Filament?
We're trying to achieve the following scenario:
BulkAction::make('download_reports') ->label('Download Selected') ->visible(function ($selectedRecords) { // If single record selected, hide if already downloaded if ($selectedRecords->count() === 1) { return !$selectedRecords->first()->downloaded; } // If multiple records selected, and all have been downloaded, hide the button if ($selectedRecords->every(fn ($record) => $record->downloaded)) { return false; } return true; })
BulkAction::make('download_reports') ->label('Download Selected') ->visible(function ($selectedRecords) { // If single record selected, hide if already downloaded if ($selectedRecords->count() === 1) { return !$selectedRecords->first()->downloaded; } // If multiple records selected, and all have been downloaded, hide the button if ($selectedRecords->every(fn ($record) => $record->downloaded)) { return false; } return true; })
However, it appears that we cannot access the selected records inside the
->visible()
->visible()
attribute, as
$selectedRecords
$selectedRecords
always returns
null
null
.
Is there a way to access the selected records in the visible attribute, or is this not supported?
I understand there is a
checkIfRecordIsSelectableUsing
checkIfRecordIsSelectableUsing
attribute at table level, however that hides all the bulk actions.