conditionally show bulkactions based on the data of the selected records

Is is possible to show only to show a bulkaction if the selected records meet a criteria
                BulkAction::make('Voortoekenning')
                    ->action(function (Collection $records, array $data): void {
                        foreach ($records as $record) {
                            if ($record->isStatus('Ingevoerd') || $record->setStatus('Aangeboden')) {
                                if ($data['maakster_id']) {
                                    $record->Gebruiker_Voortoekenning = $data['maakster_id'];
                                }
                                $record->Datum_Verlopen_Voortoekenning = $data['verloopdatum'];
                                $record->setStatus('Aangeboden');

                                $record->save();
                            }
                        }
                    })
                    ->form([
                        Select::make('maakster_id')
                            ->label('Maakster')
                            ->options(User::query()->where('voortoekenning', '1')->pluck('name', 'id'))
                            ->preload(),
                        DateTimePicker::make('verloopdatum')->label('Verloop datum')->displayFormat('d-m-Y H:i')
                            ->minDate(now())
                            ->maxDate(now()->addDays(7))
                            ->required(),
                    ]),

I only want to see this action if all records that are selected have the state $record->isStatus('Ingevoerd'). something like
->showCondintion(
function (Collection $records) {
  $show=$true;
  foreach ($records as $record) {
    if ($record->correctstatus){$show = $false;}
  }
  return $show;
})


I have multiple bulk actions that act on different status values so I would like to hide actions that are not possible/applicable at that moment
Was this page helpful?