beforeDelete() runs custom logic before a delete operation.
Purpose
beforeDelete() runs custom logic before a delete operation. It lets a controller customize Aksara Core behavior while keeping the request inside the built-in CRUD, rendering, permission, validation, and response pipeline.
When to Use
Override this method when a module needs custom side effects or checks around create, update, or delete operations.
Reference
beforeDelete()
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| None | - | - | - | This method does not accept parameters. |
Return Value
mixed|void
Hooks do not need to return anything. Return an Aksara response or exception object only when the CRUD operation must be stopped.
Behavior
beforeDelete() is an override hook. Core calls it automatically at the matching point in the create, update, or delete flow when the method exists on the controller.
Basic Usage
protected function beforeDelete()
{
log_message('info', 'beforeDelete hook executed.');
}
Advanced Usage
protected function beforeDelete()
{
if (! get_userdata('is_admin')) {
return throw_exception(403, phrase('Only administrators may delete this record.'));
}
}
Complete Example
namespace Modules\Orders\Controllers;
use Aksara\Laboratory\Core;
class Orders extends Core
{
protected function beforeDelete()
{
if (! get_userdata('is_admin')) {
return throw_exception(403, phrase('Only administrators may delete this record.'));
}
}
public function index()
{
return $this->render('orders');
}
}
Result
The custom hook logic runs automatically during the matching CRUD operation. If the hook returns a blocking response, the operation can be stopped.
Notes
- Hooks are optional; define them only when the module needs extra behavior.
- A hook may return an Aksara error/response object when the operation must stop.
Common Mistakes
- Making the hook public when it is intended to be a protected controller method.
- Performing slow external work synchronously without considering request timeout.
