© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
15 replies
HenkN

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(),
                    ]),
                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;
})
->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
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Accessing Selected Records on Page without BulkActions
FilamentFFilament / ❓┊help
5mo ago
BulkAction options based on selected records.
FilamentFFilament / ❓┊help
2y ago
Conditionally show widget based on record
FilamentFFilament / ❓┊help
2y ago
Show infolist conditionally based on user role
FilamentFFilament / ❓┊help
3y ago