If we wish to add a new bulk action to a screen within the admin, all we have to do is create the bulk action using the BulkAction facade. The bulk action also requires a specific Resource List, for example for Products.
BulkAction::create(BulkActionClass::class, ResourceList::class)
->permissions('bulkaction.permission')
->title('Title');
The above code would be instantiated within a Service Provider, whether it is a module service provider or the AppServiceProvider.
Example:
If we were to create a new bulk action for exporting products, we would first need to create a class extending BulkActionJob:
BulkAction::create(ExportProducts::class, ProductsResourceList::class)
->notRunnable()
->permissions('products.export')
->title('Export products');
Properties
Bulk Actions have a number of properties, each responsible for affecting a different aspect of the bulk action.
Wide Content
We can choose to display the contents of our bulk action in a wider container, which can prove to be more useful for certain modules. In order to display its contents in a container stretched to the width of the screen, apply the following function to the facade while creating it:
BulkAction::create(BulkActionClass::class, ResourceList::class)
->wideContent()
->permissions('bulkaction.permission')
->title('Title');
Runnable & Not Runnable
Not every bulk action is the same, and it’s possible to remove the Run button from the bulk action in order to replace it with a custom button, for example calling the API. In order to remove the built-in Run button for a particular bulk action, apply the following function to the facade while creating it:
BulkAction::create(BulkActionClass::class, ResourceList::class)
->notRunnable()
->permissions('bulkaction.permission')
->title('Title');
Confirm
We can set the bulk action to prompt the user before performing its intended action by simply chaining a method to the BulkAction creation:
BulkAction::create(BulkActionClass::class, ResourceList::class)
->confirm()
->permissions('bulkaction.permission')
->title('Title');
The prompt will now ask the user if they are sure of their selection.
Title
We can set a custom title/main heading for the bulk action content, this can be done by chaining a function to the facade we use for creating the bulk action, e.g.:
BulkAction::create(BulkActionClass::class, ResourceList::class)
->title('Your title')
->permissions('bulkaction.permission')
->title('Title');
View
Aero has the ability to display a specific view when it performs the bulk action, this can be done by chaining a function to the facade we use for creating the bulk action, e.g.:
BulkAction::create(BulkActionClass::class, ResourceList::class)
->view(‘namespace::bulk.form’)
->permissions('bulkaction.permission')
->title('Title');