Main Navigation

\Aksara\Laboratory\Core->insertData()

The documentation and cheat sheet of our framework

insertData() inserts a row through the Core CRUD pipeline.

Purpose

insertData() inserts a row through the Core CRUD pipeline. 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

Use it when you need to extend the Core CRUD flow while keeping Aksara validation, hooks, formatting, and response handling.

Reference

insertData(?string $table = null, array $data = [])

Parameters

ParameterTypeRequiredDefaultDescription
$table?stringNonullDatabase table name.
$dataarrayNo[]Data row, rows, or submitted values.

Return Value

object|null

Returns an Aksara response object on success or failure, or null when the flow has no explicit response to return.

Behavior

insertData() runs inside the Core data/rendering pipeline. Depending on the method, it may format data, validate input, execute a CRUD operation, or return an Aksara response.

[!WARNING]

Direct CRUD helpers still execute Core hooks and response handling. Use them only when the normal render() flow is not enough.

Basic Usage

$result = $this->insertData('orders', ['status' => 'draft']);

Advanced Usage

$this->setValidation('status', 'required|in_list[draft,paid,cancelled]');

return $this->render('orders');

Complete Example

namespace Modules\Orders\Controllers;

use Aksara\Laboratory\Core;

class Orders extends Core
{
    public function process()
    {
        $result = $this->insertData('orders', ['status' => 'draft']);

        return throw_exception(200, phrase('The request has been processed.'));
    }
}

Result

The Core pipeline returns the documented value while preserving Aksara validation, hook, permission, audit, and response behavior where applicable.

Notes

  • These methods are usually called by render() internally, but can be useful for advanced modules.
  • Keep direct calls close to the surrounding CRUD logic so the response flow is easy to audit.

Common Mistakes

  • Bypassing Core validation or hooks unintentionally by writing directly to the database.
  • Returning raw arrays when the caller expects an Aksara response object.

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