Laravel Nova provides a feature where you can create custom actions to modify multiple table records at the same time. Here, I am trying to create a custom action to approve registered recipients in one of my applications.

To create the action I have to run the following command.

php artisan nova:action ApproveRecipient

A file named ApproveRecipient.php will be created in app/Nova/Actions/

Now I have to edit this file and put the code to make changes to the model when I run this action. Here, I am assigning the logged in user id as the value of approved_by column.

...

public function handle(ActionFields $fields, Collection $models)
{
    foreach ($models as $model) {
        $model->approved_by = auth()->id();
        $model->save();
    }
}

...

Next step is to add the to Nova resource. Open the file app/Nova/Recipient.php and add the following code in actions method.

...

public function actions(Request $request)
{
    return [
        new Actions\ApproveRecipient
    ];
}

...

In Nova dashboard, if you click one of the records from Recipients table, you can now see the action,

Some actions might take a while to complete. Hence, if you want the actions to run on a queue, you should implement ShouldQueue interface in your action class.

...

use Illuminate\Contracts\Queue\ShouldQueue;

class ApproveRecipient extends Action implements ShouldQueue
{
    use InteractsWithQueue, Queueable;
    
...

To use Laravel queues, you have to make jobs table by running the following command.

php artisan queue:table

Run the migration command.

php artisan:migrate

Now open the .env file and change the queue connection as database.

...

QUEUE_CONNECTION=database

...

Before running the nova action on queue, run the following command.

php artisan queue:work

Thats it. Enjoy!