description | keywords |
---|---|
The Splade Table component supports Bulk Actions. It can perform the action on the selected rows, on all rows on the current page, or on all rows on all pages. |
laravel datatables bulk actions, laravel datatables actions, laravel table bulk action, laravel tables bulk action |
The Table component supports performing Bulk Actions. First, you must register a supporting route using the spladeTable()
method on the Route
facade. As of version 0.6, the automatic installer does this for you. If you need to register the route manually, make sure it uses the web
and splade
Middleware, for example, in web.php
:
Route::middleware('splade')->group(function () {
Route::spladeTable();
});
You may configure a Bulk Action on the SpladeTable
instance:
public function configure(SpladeTable $table)
{
$table->bulkAction('Touch timestamp', function (Project $project) {
$project->touch();
});
}
The bulkAction
method has additional before
and after
arguments. You may use this to show a Toast when the action has finished, or for example, to perform some logging:
$table->bulkAction(
label: 'Touch timestamp',
each: fn (Project $project) => $project->touch(),
before: fn () => info('Touching the selected projects'),
after: fn () => Toast::info('Timestamps updated!')
);
You may use the confirm
argument to show a confirmation dialog before Splade performs the action:
$table->bulkAction(
label: 'Touch timestamp',
each: fn (Project $project) => $project->touch(),
confirm: true
);
In addition, you may customize the confirmation dialog:
$table->bulkAction(
label: 'Touch timestamp',
each: fn (Project $project) => $project->touch(),
confirm: 'Touch projects',
confirmText: 'Are you sure you want to touch the projects?',
confirmButton: 'Yes, touch all selected rows!',
cancelButton: 'No, do not touch!',
);
It's even possible to require the user to confirm their password within the confirmation dialog. First, you must register a supporting route using the spladePasswordConfirmation()
method on the Route
facade. As of version 1.2.2, the automatic installer does this for you. If you need to register the route manually, make sure it uses the web
Middleware, for example, in web.php
:
Route::spladePasswordConfirmation();
Now you may set the requirePassword
argument to true
:
$table->bulkAction(
label: 'Delete projects',
each: fn (Project $project) => $project->delete(),
confirm: true,
requirePassword: true
);
Just like Form Requests, you may use the authorize
method to determine if the user has the authority to perform a Bulk Action:
class Projects extends AbstractTable
{
public function authorize(Request $request)
{
return $request->user()->is_admin;
}
}