Defining bulk actions

Just like your fields fields, you should define these in your Table's setup() method.

You do this by calling $this->defineAction($slug, $title, $callable = false, array $messages = null)

$slug

This will be used for routing the request to perform the action you're defining.

$title

This parameter will get rendered in the action's list.

$callable optional

The $callable parameter let's you define a function that actually performs the action.

There are several ways of assigning it a function

false
By default no function is assigned, if there isn't, your Table is going to look for a specific method on its object instance.

To be more specific it will look for a method in this format: $callable = 'perform' . studly_case($slug);

Here are a few examples of how the slug would be transformed:

  • delete -> performDelete
  • activate_user -> performActivateUser

other callable types
The other options can be: an anonymous function, a string or array as described here

$messages optional

Here you could define the following messages:

keydescription
activeThe message that's displayed when the request is set to the server
successThe message that's returned on a successful request
errorThe default message that's returned when an error occured

However, if one, or all aren't defined, defaults will be used.

Performing an action

As we previously saw, there are several ways you can define your action's callable.

Your callable will always get 1 parameter assigned, which is an array containing primary keys, how these get processed is up to you.

Return response

Most of the time it's enough to return a boolean upon a successful or errored request.

When a boolean is returned, it will will use the default success or error message that was declared when you called $this->defineAction().

If you return a string your Table will think an error occured and use that string as the error message in the user's front-end.

📘

Note

Exceptions do get caught and will show as "An error occurred :/" in the front-end. for debugging purposes the actual error message gets sent along under the error key.