Create
and Update
forms end in a Save button with a drop menu. Every option in that dropdown is a SaveAction - they determine where the user is redirected after the saving is complete.
There are four save actions registered by Backpack by default. They are:
save_and_back
(Save your entity and go back to previous URL)save_and_edit
(Save and edit the current entry)save_and_new
(Save and go to create new entity page)save_and_preview
(Save and go to show the current entity)Inside your CrudController, inside your setupCreateOperation()
or setupUpdateOperation()
methods, you can change what save buttons are shown for each operation by using the methods below:
Adds a new SaveAction to the "Save" button/dropdown.
$this->crud->addSaveAction([
'name' => 'save_action_one',
'redirect' => function($crud, $request, $itemId) {
return $crud->route;
}, // what's the redirect URL, where the user will be taken after saving?
// OPTIONAL:
'button_text' => 'Custom save message', // override text appearing on the button
// You can also provide translatable texts, for example:
// 'button_text' => trans('backpack::crud.save_action_one'),
'visible' => function($crud) {
return true;
}, // customize when this save action is visible for the current operation
'referrer_url' => function($crud, $request, $itemId) {
return $crud->route;
}, // override http_referrer_url
'order' => 1, // change the order save actions are in
]);
The same principle of addSaveAction([])
but for adding multiple actions with only one crud call.
$this->crud->addSaveActions([
[
'name' => 'save_action_one',
'visible' => function($crud) {
return true;
},
'redirect' => function($crud, $request, $itemId) {
return $crud->route;
},
],
[
'name' => 'save_action_two',
'visible' => function($crud) {
return true;
},
'redirect' => function($crud, $request, $itemId) {
return $crud->route;
},
],
]);
This allows you to replace the current save actions with the ones provided in an array.
$this->crud->replaceSaveActions(
[
'name' => 'save_action_one',
'visible' => function($crud) {
return true;
},
'redirect' => function($crud, $request, $itemId) {
return $crud->route;
},
],
);
This allows you to remove a specific save action from the save actions array. Provide the name of the save action that you would like to remove.
$this->crud->removeSaveAction('save_action_one');
The same principle as removeSaveAction()
but to remove multiple actions at same time. You should provide an array with save action names.
$this->crud->removeSaveActions(['save_action_one','save_action_two']);
You can specify a certain order for a certain save action.
$this->crud->orderSaveAction('save_action_one', 1);
We will setup the save action in the desired order and try to re-order the other save actions accordingly. If you want more granular control over all save actions order, you can define order
when creating the save action, or use orderSaveActions()
Allows you to reorder multiple save actions at same time. You can use it by either specifying only the names of the save actions, in the order you want, or by specifying their order number too:
// make save actions show up in this order
$this->crud->orderSaveActions(['save_action_one','save_action_two']);
// or
$this->crud->orderSaveActions(['save_action_one' => 3,'save_action_two' => 2]);
Alias for replaceSaveActions(array $saveActions)
.
Then you'll love our premium add-ons - productivity tools and tons of new features.