Page actions

Let's see users/index.php actions section. Currently it contains only from DELETE method, which contain only one action named 'delete'.

'delete' => [ // request method

    'delete' => [ // action name
        'permission' => 'admin:users_delete',
        'rules' => [],
        'closure' => function () {
            User::where('id', request()->id)->delete();

            // return data
        }
    ],

]

Each action may contains from:

  • 'permission' - which is checked when user tries to perform action.
  • 'rules' - may contain validation rules, which can be stored in array or closure, it is not required by default.
  • 'closure' - logic which should be performed when this action happens.
  • 'messages' - may contain error messages for validation errors, which can be stored in array or closure, it is not required by default.
  • 'attributes' - may contain attribute names for validation errors, which can be stored in array or closure, it is not required by default.
  • 'request' - may contain name of the request class, which will contain all validation logic.

More about requests you can find in Laravel docs.

Return formats

Now let's see return statement in delete action, which looks like:

return [
    'status' => 'success',
    'reload' => true,
    'swal' => [
        'title' => 'Deleted',
        'text' => 'User was deleted successfully',
        'type' => 'success'
    ]
];

For actions, which is called by javascript functions.request() function, may be defined some custom actions, which will be processed by javascript after getting the response.

Here is a description of return data:

  • 'status' - if status != success then user will see notification with text "An error occurred while executing the request". If request status != 200, user will see body of the response.
  • 'notification' - array, which should contain properties:

    • 'text' which has to be shown to user
    • 'type' of notification, which has be alert, success, warning, error, info or information.
  • 'swal' - tells javascript to show swal window to user, after success request. It also must be an array with properties:

    • 'title' of window.
    • 'text' text in window.
    • 'type' of window, which may be success, error, warning, info or question.
  • 'reload' - boolean, which can tell javascript to reload page after receiving a response.

  • 'redirect' - should contain the link to which you want to redirect user.

Note: if reload or redirect is used with swal option, it will be performed only after closing swal window.