Main Navigation

\Aksara\Laboratory\Core->beforeDelete()

The documentation and cheat sheet of our framework

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

ParameterTypeRequiredDefaultDescription
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.

Related Methods

Available Methods

addButton addClass addDropdown addField addFilter addSubmitButton addToolbar afterDelete afterInsert afterUpdate allowPublicFormSubmission allowTokenFrom beforeDelete beforeInsert beforeUpdate columnOrder columnSize databaseConfig debug defaultValue deleteBatch deleteData distinct fieldAppend fieldOrder fieldPosition fieldPrepend fieldSize formCallback from fromSubquery getMethod gridView groupBy groupEnd groupField groupStart having havingGroupEnd havingGroupStart havingIn havingLike havingNotIn ignoreQueryString insertData insertId itemReference join like limit mergeContent mergeField modalSize notGroupStart notHavingGroupStart notHavingLike notLike offset orGroupStart orHaving orHavingGroupStart orHavingIn orHavingLike orHavingNotIn orLike orNotGroupStart orNotHavingGroupStart orNotHavingLike orNotLike orWhere orWhereIn orWhereNotIn orderBy parentModule permitUpsert render renderForm renderRead renderTable restrictOnDemo searchable select selectAvg selectCount selectMax selectMin selectSubquery selectSum serialize serializeRow setAiContext setAlias setAttribute setAutocomplete setBreadcrumb setButton setDefault setDescription setField setHeading setIcon setMessages setMethod setOptionLabel setOutput setPermission setPlaceholder setPrimary setRelation setTemplate setTheme setTitle setTooltip setUploadPath setValidation sortable table unsetColumn unsetDelete unsetField unsetMethod unsetRead unsetSelect unsetToolbar unsetTruncate unsetUpdate unsetView updateData validToken validateForm verticalSchema viewOrder where whereIn whereNotIn