© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•5mo ago
Gangus

Do not run BulkAction for any records if some do not pass policy validation

Hey Filament Discord! First of all, huge thanks for all maintainers of this package.

I have a question regarding bulk actions. I saw that it is possible to individually authorize them for each record, which is cool:
BulkAction::make('do_some_stuff')
        ->authorizeIndividualRecords('doStuff')
        ->action(self::executeAction(...))
BulkAction::make('do_some_stuff')
        ->authorizeIndividualRecords('doStuff')
        ->action(self::executeAction(...))

In this case,
executeAction
executeAction
will only receive the records which pass
doStuff
doStuff
, and will only execute my action for those.

However, in such cases where some records get thrown out, I would like if the action did not execute for any records, not even for those that passed the policy.

I saw that I can inject the
$records
$records
and
$action
$action
in my
action()
action()
callback, and can look for differences if needed:
use Filament\Actions\Action;

private static function executeAction(Collection $records Action $action): void
{
    $originallySelectedRecords = $action->getSelectedRecords();

    if ($records->count() < $originallySelectedRecords->count()) {
        // Uh oh, some did not pass the policy. I would not like to run this at all, not even for those that did.
        return;
    }
}
use Filament\Actions\Action;

private static function executeAction(Collection $records Action $action): void
{
    $originallySelectedRecords = $action->getSelectedRecords();

    if ($records->count() < $originallySelectedRecords->count()) {
        // Uh oh, some did not pass the policy. I would not like to run this at all, not even for those that did.
        return;
    }
}

But it'd be a bit troublesome to insert this logic into all of my bulk actions.

So my question is, is there a more elegant, Filament way I can do this?
Refusing to run the action when some records do not pass a policy?

Or would I need to extend
BulkAction
BulkAction
and add some custom logic?
If so, could I get some tips on how I can cleanly do it?

My reason for wanting to do this is that I think it's simpler to understand for the end user.
"Your selection mixed in some incorrect records, so nothing will be done, please try again." is the way I want to go by.

Thank you for your help in advance.
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

DeleteBulkAction do not check for delete_any policy
FilamentFFilament / ❓┊help
2mo ago
How to run a BulkAction on selected to table records
FilamentFFilament / ❓┊help
2y ago
How to get selected records without any BulkAction or Action?
FilamentFFilament / ❓┊help
6mo ago
Any way to get selected records on an bulkaction form?
FilamentFFilament / ❓┊help
12mo ago