callbackBeforeDelete

callbackBeforeDelete(callable $callback)

The callback that will be used right before the delete. The only parameter that the state will have is the primary key value.

Example:

$crud->callbackBeforeDelete(function ($stateParameters) {
    // Your code here    

    return $stateParameters;
});

The $stateParameters variable is at the below form:

$stateParameters = (object)[
    'primaryKeyValue' => '1234'
];

Example

Below there is a working example of the callbackBeforeDelete method.

$crud->setTable('offices');
$crud->setSubject('Office', 'Offices');
$crud->columns(['city','country','phone','addressLine1','postalCode']);

$crud->callbackBeforeDelete(function ($stateParameters) {
  // Custom error messages are only available on Grocery CRUD Enterprise
  $errorMessage = new \GroceryCrud\Core\Error\ErrorMessage();
  return $errorMessage->setMessage("You don't have permissions to delete this office\n");
});

$output = $crud->render();