PHP code example of mzgs / fastcrud

1. Go to this page and download the library: Download mzgs/fastcrud library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mzgs / fastcrud example snippets



FastCrud\Crud;

// Initialize database connection
// Supports: driver, host, port, database, username, password, options
Crud::init([
    'driver' => 'mysql',        // mysql, pgsql, sqlite
    'host' => '127.0.0.1',
    'database' => 'your_database',
    'username' => 'your_username',
    'password' => 'your_password',
]);

// Create and render a CRUD table - that's it!
echo new Crud('users')->render();

use FastCrud\CrudConfig;

CrudConfig::$script_url = '/vendor/fastcrud/fastcrud.js';

// Each Crud instance is independent - reuse the same connection
$users = new Crud('users');
$orders = (new Crud('orders'))->setPerPage(10)->order_by('created_at', 'desc');

echo $users->render();
echo $orders->render();

$users = (new Crud('users'))->enableAuditLog([
    'user_id' => $_SESSION['user_id'] ?? null,
]);

echo $users->render();

class CurrentUser
{
    public static function id(): ?int
    {
        return $_SESSION['user_id'] ?? null;
    }
}

$users = (new Crud('users'))->enableAuditLog([
    'user_id_callback' => [CurrentUser::class, 'id'],
]);

$orders = (new Crud('orders'))
    ->table_title('Orders')
    ->table_icon('fas fa-receipt')
    ->columns(['id', 'customer_id', 'status', 'total', 'created_at'])
    ->set_column_labels([
        'customer_id' => 'Customer',
        'created_at' => 'Created',
    ])
    ->relation('customer_id', 'customers', 'id', 'name', [], 'name ASC')
    ->search_columns(['status', 'created_at'])
    ->order_by('created_at', 'desc')
    ->limit_list([10, 25, 50, 'all'])
    ->enable_export_csv()
    ->enable_batch_delete()
    ->add_bulk_action('mark_paid', 'Mark paid', [
        'fields' => ['status' => 'paid'],
        'confirm' => 'Mark selected orders as paid?',
    ]);

echo $orders->render();

$users = (new Crud('users'))
    ->fields(['name', 'email', 'role', 'status', 'created_by'])
    ->change_type('role', 'select', 'member', [
        'options' => [
            'admin' => 'Admin',
            'member' => 'Member',
            'viewer' => 'Viewer',
        ],
    ])
    ->change_type('status', 'switch', true)
    ->validation_

function canEditRole(array $row, array $context, Crud $crud): bool
{
    return ($_SESSION['role'] ?? '') === 'admin';
}

$users = (new Crud('users'))
    ->column_visible_if('internal_notes', ($_SESSION['role'] ?? '') === 'admin')
    ->field_visible_if('salary', ($_SESSION['role'] ?? '') === 'admin', ['edit', 'view'])
    ->field_editable_if('role', 'canEditRole', 'edit');

echo $users->render();

use FastCrud\CrudConfig;

CrudConfig::$upload_path = __DIR__ . '/public/uploads';
CrudConfig::$upload_serve_path = '/uploads';
CrudConfig::$upload_max_image_size = '5MB';
CrudConfig::$upload_max_file_size = '20MB';

$products = (new Crud('products'))
    ->change_type('image', 'image', '', [
        'path' => 'products',
        'max_size' => '5MB',
        'width' => 1200,
        'height' => 800,
        'previewHeight' => 180,
    ])
    ->change_type('manual', 'file', '', [
        'path' => 'manuals',
        'accept' => 'application/pdf,.pdf',
        'max_size' => '20MB',
    ]);

echo $products->render();

class CurrentUser
{
    public static function id(): ?int
    {
        return $_SESSION['user_id'] ?? null;
    }
}

$posts = (new Crud('posts'))
    ->where('deleted_at IS NULL')
    ->enable_soft_delete('deleted_at')
    ->enableAuditLog([
        'user_id_callback' => [CurrentUser::class, 'id'],
    ]);

echo $posts->render();

use FastCrud\Crud;

function fillPostDefaults(array $fields, array $context, Crud $crud): array
{
    $fields['slug'] ??= strtolower(preg_replace('/[^a-z0-9]+/i', '-', $fields['title'] ?? ''));
    $fields['created_by'] ??= $_SESSION['user_id'] ?? null;

    return $fields;
}

function notifyPostUpdate(array $row, array $context, Crud $crud): array
{
    error_log('Post updated: ' . ($context['primary_value'] ?? 'unknown'));

    return $row;
}

$posts = (new Crud('posts'))
    ->before_create('fillPostDefaults')
    ->after_update('notifyPostUpdate');

echo $posts->render();

$orders = (new Crud('orders'))
    ->asBadge('status', [
        'paid' => ['label' => 'Paid', 'class' => 'text-bg-success'],
        'cancelled' => ['label' => 'Cancelled', 'class' => 'text-bg-danger'],
    ])
    ->asMoney('total', '$')
    ->column_summary('total', 'sum', 'Total', 2)
    ->highlight_row('status', '=', 'cancelled', 'table-danger')
    ->column_truncate('notes', 80);

echo $orders->render();

use FastCrud\Crud;

Crud::preset('admin_table', function (Crud $crud): void {
    $crud
        ->limit_list([10, 25, 50, 'all'])
        ->enable_filters()
        ->enable_export_csv()
        ->style('add_button_class', 'btn btn-sm btn-primary')
        ->text([
            'add' => 'New',
            'export_csv' => 'Download CSV',
            'no_records' => 'Nothing to show.',
        ]);
});

echo (new Crud('orders'))
    ->usePreset('admin_table')
    ->asBadge('status', ['paid' => 'text-bg-success', 'draft' => 'text-bg-secondary'])
    ->asDateTime('created_at', 'd.m.Y H:i')
    ->render();

$invoices = (new Crud('invoices'))
    ->add_link_button([
        'url' => '/invoices/{id}/preview',
        'icon' => 'fas fa-eye',
        'label' => 'Preview',
        'button_class' => 'btn btn-sm btn-outline-primary',
        'options' => ['target' => '_blank'],
    ])
    ->add_toolbar_action([
        'url' => '/invoices/create',
        'icon' => 'fas fa-plus',
        'label' => 'New Invoice',
        'button_class' => 'btn btn-primary',
    ]);

echo $invoices->render();

$customers = (new Crud('customers'))
    ->columns(['id', 'name', 'email']);

$customers->nested_table('customer_orders', 'id', 'orders', 'customer_id', function (Crud $orders): void {
    $orders
        ->columns(['id', 'status', 'total', 'created_at'])
        ->order_by('created_at', 'desc')
        ->limit(5);
});

echo $customers->render();


FastCrud\DatabaseEditor;

// Initialize with an existing PDO instance
$pdo = new PDO('mysql:host=127.0.0.1;dbname=your_database', 'your_username', 'your_password');
DatabaseEditor::init($pdo);

// Render the database editor interface
echo DatabaseEditor::render();

// Uncomment to 

use FastCrud\Crud;
use FastCrud\DatabaseEditor;

Crud::init(['database' => 'app', 'username' => 'user', 'password' => 'secret']);
DatabaseEditor::init(); // reuses previously set config
echo DatabaseEditor::render();

  $pdo = new PDO('mysql:host=localhost;dbname=my_app', 'db_user', 'db_password');
  DatabaseEditor::init($pdo);
  

  // Hero header hidden, records view enabled
  echo DatabaseEditor::render(false, true);
  

  Crud::init([
      'database' => 'app',
      'username' => 'root',
      'password' => 'secret',
  ]);
  

  $crud = Crud::fromAjax('users', $_GET['fastcrud_id'] ?? null, $_POST['config'] ?? null);
  

  Crud::preset('admin_table', fn (Crud $crud) => $crud->enable_export_csv()->enable_filters());
  

  echo (new Crud('users'))->usePreset('admin_table')->render();
  

  $crud = new Crud('users', $customPdo);
  

  $tableName = $crud->getTable();
  

  $crud->primary_key('user_id');
  

  $crud->setPerPage(25);
  

  $crud->limit(10);
  

  $crud->limit_list([5, 10, 25, 'all']);
  

  $crud->compact_pagination();
  

  $crud->setFormWidth('640px');
  $crud->setFormWidth('30%');
  

  $crud->setFormDisplayMode('modal', '640px');
  $crud->setFormDisplayMode('side', '50%');
  $crud->setFormDisplayMode('inline', '720px');
  

  $crud->inline_edit(['status', 'priority']);
  

  $crud->columns(['id', 'name', 'email']);
  

  $crud->set_column_labels(['created_at' => 'Created']);
  

  $crud->set_field_labels('phone', 'Contact Number');
  

  $crud->asMoney('total', '$');
  $crud->as_money('price', 'TRY', ['position' => 'after', 'precision' => 2]);
  

  $crud->asDate('birthday', 'd.m.Y');
  $crud->asDateTime('created_at', 'd.m.Y H:i');
  

  $crud->asBadge('status', [
      'active' => ['label' => 'Active', 'class' => 'text-bg-success'],
      'draft' => 'text-bg-secondary',
  ]);
  

  $crud->asBoolean('is_active', ['true_label' => 'Active', 'false_label' => 'Inactive']);
  

  $crud->column_pattern('email', '<a href="mailto:{raw}">{value}</a>');
  $crud->column_pattern('name', '<strong>{first_name} {last_name}</strong> ({id})');
  

  // Using a named function (function must accept 4 params: $value, $row, $column, $display)
  // $value: current cell value, $row: full row data, $column: column name, $display: formatted value
  function format_total_with_tax($value, $row, $column, $display) {
      $tax_rate = $row['tax_rate'] ?? 0;
      $total_with_tax = $value * (1 + $tax_rate / 100);
      return '$' . number_format($total_with_tax, 2);
  }
  $crud->column_callback('total', 'format_total_with_tax');
  

  $crud->column_callbacks([
      'status' => 'map_status',
      'total,subtotal' => [InvoicePresenter::class, 'formatCurrency'],
  ]);
  

  function order_status_tooltip($value, $row, $column, $display) {
      return 'Updated by ' . ($row['updated_by'] ?? 'system');
  }

  $crud->column_tooltip('status', 'order_status_tooltip');
  $crud->column_tooltip('total', 'Raw total: {raw}');
  

  $crud->column_tooltips([
      'status' => 'order_status_tooltip',
      'title,slug' => 'Current value: {value}',
  ]);
  

  // Using a named function (function must accept 1 param: $row)
  // $row: full row data array
  function compute_full_name($row) {
      return trim(($row['first_name'] ?? '') . ' ' . ($row['last_name'] ?? ''));
  }
  $crud->custom_column('full_name', 'compute_full_name');
  

  $crud->custom_columns([
      'full_name' => 'compute_full_name',
      'total_with_tax,total_without_tax' => [InvoicePresenter::class, 'formatTotals'],
  ]);
  

  $crud->column_class('status', 'text-uppercase text-success');
  

  $crud->column_width('name', '220px');
  

  $crud->column_truncate('description', 80);
  

  $crud->default_column_truncate(['length' => 120, 'suffix' => '...']);
  

  $crud->highlight('status', '=', 'pending', 'text-danger');
  $crud->highlight(['status', 'priority'], 'empty', null, 'text-muted');
  $crud->highlight('notes', 'not_contains', 'internal', 'text-danger');
  

  $crud->highlight_row('balance', 'lt', 0, 'table-danger');
  

  $crud->column_summary('total', 'sum', 'Grand Total', 2);
  

  // Using a named function (function must accept 4 params: $field, $value, $row, $mode)
  // $field: field name, $value: current value, $row: full row data, $mode: 'create'|'edit'|'view'
  function add_confirmation_checkbox($field, $value, $row, $mode) {
      return <<<HTML
          <label class="form-check-label">
              <input 
                  type="checkbox" 
                  class="form-check-input"
                  name="{$field}"
                  data-fastcrud-field="{$field}" 
                  value="1"
              > 
              I confirm this action
          </label>
      HTML;
  }
  $crud->custom_field('confirmation', 'add_confirmation_checkbox');
  

  // Using a named function (function must accept 4 params: $field, $value, $row, $mode)
  // $field: field name, $value: current value, $row: full row data, $mode: 'create'|'edit'|'view'
  function create_color_picker($field, $value, $row, $mode) {
      $value = htmlspecialchars($value ?? '#000000');
      return <<<HTML
          <input
              type="color"
              class="form-control form-control-color"
              name="{$field}"
              data-fastcrud-field="{$field}"
              value="{$value}"
              title="Choose your color"
          >
      HTML;
  }
  $crud->field_callback('color', 'create_color_picker');
  

  $crud->fields_callbacks([
      'color' => 'create_color_picker',
      'status,priority' => 'decorate_badges',
  ]);
  

  $crud->fields(['name', 'email', 'phone'], false, 'Details');
  

  $crud
      ->fields('name,email,timezone,locale')
      ->form_section('profile', [
          'title'       => 'Profile',
          'description' => 'Primary contact details',
          'icon'        => 'fas fa-id-card',
          'class'       => 'card shadow-sm',
          'title_class' => 'px-3 pt-3',
          'fields'      => ['name', 'email'],
      ])
      ->form_section('preferences', [
          'title'        => 'Preferences',
          'fields'       => ['timezone', 'locale'],
          'collapsible'  => true,
          'start_collapsed' => true,
      ], ['edit', 'view']);
  

  $crud->default_tab('Details', ['create', 'edit']);
  

  // Text input (default)
  $crud->change_type('username', 'text');
  
  // Textarea for longer content
  $crud->change_type('description', 'textarea', '', ['rows' => 5]);
  
  // Select dropdown with options
  $crud->change_type('status', 'select', 'active', ['options' => ['active' => 'Active', 'inactive' => 'Inactive']]);
  
  // Rich text editor (WYSIWYG with TinyMCE)
  $crud->change_type('content', 'rich_editor', '', ['height' => 400]);
  
  // Image upload (basic)
  $crud->change_type('avatar', 'image', '', ['path' => 'avatars']);
  
  // Multiple images and files: thumbnail lists with drag-and-drop reordering
  $crud->change_type('gallery', 'images', '', ['path' => 'gallery']);
  $crud->change_type('attachments', 'files', '', ['accept' => '.pdf,.docx', 'max_size' => '10MB']);

  // Image upload with transforms
  $crud->change_type('product_image', 'image', '', [
      'path' => 'products',
      'max_size' => '5MB',
      'width' => 1200,
      'height' => 800,
      'crop' => false,
      'thumbs' => [
          [
              'width' => 300,
              'height' => 200,
              'crop' => true,
              'marker' => '_medium',
              'folder' => 'medium'
          ],
          [
              'width' => 150,
              'height' => 150,
              'crop' => true,
              'marker' => '_thumb',
              'folder' => 'thumbs'
          ]
      ],
      'placeholder' => 'Upload product image',
      'class' => 'product-image-uploader'
  ]);
  
  // Switch/toggle button
  $crud->change_type('is_featured', 'switch', false);
  
  // Number input with constraints
  $crud->change_type('price', 'number', 0, ['step' => 'any', 'min' => 0, 'max' => 1000]);
  
  // Date picker
  $crud->change_type('birth_date', 'date');
  
  // DateTime picker
  $crud->change_type('created_at', 'datetime');
  
  // Color picker
  $crud->change_type('theme_color', 'color', '#000000');
  
  // JSON editor with syntax highlighting
  $crud->change_type('metadata', 'json', '{}');

  // Password input; hashes with password_hash (defaults to PASSWORD_BCRYPT)
  $crud->change_type('password', 'password', '', [
      'placeholder' => 'Set a password',
      'algorithm' => PASSWORD_BCRYPT, // optional, accepts PASSWORD_* constants or aliases
      'cost' => 12,                    // optional password_hash option shortcut
  ]);
  

  $definition = $crud->getChangeTypeDefinition('avatar');
  

  $crud->pass_var('updated_by', Auth::id());
  

  $crud->pass_default('status', 'pending', 'create');
  

  $crud->readonly(['email'], ['edit', 'view']);
  

  $crud->disabled('type', 'create');
  

  $crud->field_visible_if('salary', 'canViewSalary', ['edit', 'view']);
  

  $crud->field_editable_if('role', ($_SESSION['role'] ?? '') === 'admin', 'edit');
  

  $crud->column_visible_if('internal_notes', ($_SESSION['role'] ?? '') === 'admin');
  

  $crud->validation_

  $crud->validation_pattern('phone', '/^\+?[0-9]{7,15}$/');
  

  $crud->max_char('title', 120);
  $crud->max_chars(['first_name', 'last_name'], 60, ['create', 'edit']);
  

  $crud->unique('email', ['create', 'edit']);
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: array of field values to be inserted
  // $context: ['operation'=>'insert', 'stage'=>'before', 'table'=>'...', 'mode'=>'create', 'primary_key'=>'...', 'fields'=>[...], 'current_state'=>[...]]
  // $crud: Crud instance
  function add_timestamps($payload, $context, $crud) {
      $payload['created_at'] = date('Y-m-d H:i:s');
      $payload['created_by'] = $_SESSION['user_id'] ?? null;
      return $payload; // Return modified payload or false to cancel
  }
  $crud->before_insert('add_timestamps');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: the inserted record data array
  // $context: ['operation'=>'insert', 'stage'=>'after', 'table'=>'...', 'mode'=>'create', 'primary_key'=>'...', 'primary_value'=>123, 'fields'=>[...], 'row'=>[...]]
  // $crud: Crud instance
  function log_new_user($payload, $context, $crud) {
      $primaryValue = $context['primary_value'] ?? 'unknown';
      error_log("New user created: ID {$primaryValue}, Email: " . ($payload['email'] ?? 'N/A'));
      return $payload; // Return payload (modifications allowed) or null
  }
  $crud->after_insert('log_new_user');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: array of field values to be inserted
  // $context: ['operation'=>'insert', 'stage'=>'before', 'table'=>'...', 'mode'=>'create', 'primary_key'=>'...', 'fields'=>[...], 'current_state'=>[...]]
  // $crud: Crud instance
  function prepare_form_data($payload, $context, $crud) {
      $payload['created_by'] = $_SESSION['user_id'] ?? null;
      $payload['ip_address'] = $_SERVER['REMOTE_ADDR'] ?? null;
      return $payload; // Return modified payload or false to cancel
  }
  $crud->before_create('prepare_form_data');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: the inserted record data array
  // $context: ['operation'=>'insert', 'stage'=>'after', 'table'=>'...', 'mode'=>'create', 'primary_key'=>'...', 'primary_value'=>123, 'fields'=>[...], 'row'=>[...]]
  // $crud: Crud instance
  function send_welcome_email($payload, $context, $crud) {
      if (!empty($payload['email'])) {
          mail($payload['email'], 'Welcome!', 'Thank you for registering.');
      }
      return $payload; // Return payload (modifications allowed) or null
  }
  $crud->after_create('send_welcome_email');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: array of field values to be updated
  // $context: ['operation'=>'update', 'stage'=>'before', 'table'=>'...', 'primary_key'=>'...', 'primary_value'=>123, 'mode'=>'edit', 'current_row'=>[...], 'fields'=>[...]]
  // $crud: Crud instance
  function update_timestamp($payload, $context, $crud) {
      $payload['updated_at'] = date('Y-m-d H:i:s');
      $payload['updated_by'] = $_SESSION['user_id'] ?? null;
      return $payload; // Return modified payload or false to cancel
  }
  $crud->before_update('update_timestamp');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: the updated record data array
  // $context: ['operation'=>'update', 'stage'=>'after', 'table'=>'...', 'primary_key'=>'...', 'primary_value'=>123, 'mode'=>'edit', 'changes'=>[...], 'previous_row'=>[...], 'row'=>[...]]
  // $crud: Crud instance
  function notify_status_change($payload, $context, $crud) {
      $changes = $context['changes'] ?? [];
      $primaryValue = $context['primary_value'] ?? 'unknown';
      if (isset($changes['status'])) {
          error_log("Status changed for record {$primaryValue}: " . ($payload['status'] ?? 'N/A'));
      }
      return $payload; // Return payload (modifications allowed) or null
  }
  $crud->after_update('notify_status_change');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: current record data to be deleted
  // $context: ['operation'=>'delete', 'stage'=>'before', 'table'=>'...', 'primary_key'=>'...', 'primary_value'=>123, 'mode'=>'hard'|'soft']
  // $crud: Crud instance
  function check_delete_permission($payload, $context, $crud) {
      if (($payload['created_by'] ?? null) !== ($_SESSION['user_id'] ?? null)) {
          return false; // Return false to cancel deletion
      }
      return $payload; // Return payload to continue
  }
  $crud->before_delete('check_delete_permission');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: the deleted record data
  // $context: ['operation'=>'delete', 'stage'=>'after', 'table'=>'...', 'primary_key'=>'...', 'primary_value'=>123, 'deleted'=>true, 'mode'=>'hard'|'soft', 'row'=>[...]]
  // $crud: Crud instance
  function cleanup_files($payload, $context, $crud) {
      if ($context['deleted'] && !empty($payload['avatar_path'])) {
          @unlink($payload['avatar_path']); // Clean up associated files
      }
      return null; // Return value ignored for after_delete
  }
  $crud->after_delete('cleanup_files');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: ['page'=>1, 'per_page'=>20, 'search_term'=>'...', 'search_column'=>'...']
  // $context: ['operation'=>'fetch', 'stage'=>'before', 'table'=>'...', 'id'=>'...', 'resolved'=>[...]]
  // $crud: Crud instance
  function apply_user_filter($payload, $context, $crud) {
      // Add user-specific filtering to the fetch operation
      $payload['user_filter'] = $_SESSION['user_id'] ?? 0;
      return $payload; // Return modified payload
  }
  $crud->before_fetch('apply_user_filter');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: ['rows'=>[...], 'columns'=>[...], 'pagination'=>[...], 'meta'=>[...]]
  // $context: ['operation'=>'fetch', 'stage'=>'after', 'table'=>'...', 'id'=>'...', 'resolved'=>[...]]
  // $crud: Crud instance
  function add_computed_fields($payload, $context, $crud) {
      if (isset($payload['rows'])) {
          foreach ($payload['rows'] as &$row) {
              $row['full_name'] = trim(($row['first_name'] ?? '') . ' ' . ($row['last_name'] ?? ''));
          }
      }
      return $payload; // Return modified payload
  }
  $crud->after_fetch('add_computed_fields');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: ['primary_key_column'=>'id', 'primary_key_value'=>123]
  // $context: ['operation'=>'read', 'stage'=>'before', 'table'=>'...', 'id'=>'...']
  // $crud: Crud instance
  function log_record_access($payload, $context, $crud) {
      $primaryValue = $payload['primary_key_value'] ?? 'unknown';
      error_log("User " . ($_SESSION['user_id'] ?? 'anonymous') . " accessing record {$primaryValue}");
      return $payload; // Return payload or false to cancel read
  }
  $crud->before_read('log_record_access');
  

  // Using a named function (function must accept 3 params: $payload, $context, $crud)
  // $payload: ['row'=>[...], 'primary_key_column'=>'id', 'primary_key_value'=>123]
  // $context: ['operation'=>'read', 'stage'=>'after', 'table'=>'...', 'id'=>'...', 'found'=>true]
  // $crud: Crud instance
  function add_permissions($payload, $context, $crud) {
      if (isset($payload['row']) && $context['found']) {
          $payload['row']['can_edit'] = ($payload['row']['created_by'] ?? null) === ($_SESSION['user_id'] ?? null);
      }
      return $payload; // Return modified payload
  }
  $crud->after_read('add_permissions');
  

  $crud->table_title('Customer Accounts');
  

  $crud->hide_table_title();
  

  $crud->table_tooltip('Live customer data');
  

  $crud->table_icon('fas fa-users');
  

  $crud->enable_add(false);
  

  $crud->enable_view(true, 'status', 'equals', 'active');
  

  $crud->enable_edit(true, 'locked', 'equals', 0);
  

  $crud->enable_delete(true, 'status', 'not_equals', 'archived');
  

  $crud->enable_duplicate(true, 'type', 'equals', 'template');
  

  $crud->enable_batch_delete();
  

  $crud->add_bulk_action('flag', 'Flag Selected', [
      'fields'  => ['flagged' => 1],
      'confirm' => 'Flag all chosen records?',
  ]);
  

  $crud->set_bulk_actions([
      ['name' => 'close', 'label' => 'Close', 'fields' => ['open' => 0]],
  ]);
  

  $crud->enable_soft_delete('deleted_at', ['mode' => 'timestamp']);
  $crud->enable_soft_delete('is_deleted', ['mode' => 'literal', 'value' => 1]);
  

  $crud->set_soft_delete_assignments([
      ['column' => 'deleted_at', 'mode' => 'timestamp'],
      'deleted_by' => ['mode' => 'literal', 'value' => Auth::id()],
  ]);
  

  $crud->disable_soft_delete();
  
php
  $crud->enable_delete_confirm(false);
  
php
  $crud->enable_export_csv();
  
php
  $crud->add_toolbar_html('<div class="badge text-bg-info">Synced</div>');
  
php
  $crud->enable_select2(true); // Use Select2 for this table
  $crud->enable_select2(false); // Disable Select2 for this table
  
php
  $crud->order_by(['status' => 'asc', 'created_at' => 'desc']);
  
php
  $crud->enable_filters(); // enable filters UI
  
php
  $crud->disable_sort(['notes']);
  
php
  $crud->hide_search();
  
php
  $crud->no_quotes('JSON_EXTRACT(meta, "$.flag")');
  
php
  $crud->where('status = "active"');
  
php
  $crud->or_where('role = "admin"');
  
php
  $crud->join('role_id', 'roles', 'id', 'r');
  
php
  $crud->relation('country_id', 'countries', 'id', 'name', ['active' => 1]);
  
php
  $crud->query('SELECT * FROM view_users');
  
php
  $crud->nested_table('orders', 'id', 'orders', 'user_id', function (Crud $child) {
      $child->columns(['id', 'total'])->limit(5);
  });
  
php
  echo $crud->render();
  
php
  $componentId = $crud->getId();
  
php
  $payload = $crud->getTableData(1, 10, 'sam', 'name');
  
php
  $updated = $crud->updateRecord('id', 5, ['status' => 'active']);
  
php
  $crud->deleteRecord('id', 9);
  
php
  $result = $crud->deleteRecords('id', [1, 2, 3]);
  
php
  $crud->updateRecords('id', [2, 3], ['status' => 'archived']);
  
php
  $copy = $crud->duplicateRecord('id', 7);
  
php
  $record = $crud->getRecord('id', 7);
  
php
  if (CrudAjax::isAjaxRequest()) {
      CrudAjax::handle();
  }
  
php
  if (CrudAjax::isAjaxRequest()) {
      // delegate to FastCRUD handlers
  }
  
php
  CrudAjax::autoHandle();
  
php
  CrudConfig::setDbConfig([
      'driver' => 'pgsql',
      'host' => 'db',
      'database' => 'app',
      'username' => 'user',
      'password' => 'secret',
  ]);
  
php
  $config = CrudConfig::getDbConfig();
  
php
  $path = CrudConfig::getUploadPath();
  
php
  CrudConfig::$upload_path = 'assets/uploads';
  
php
  CrudConfig::$upload_path = '/var/uploads/files';
  CrudConfig::$upload_serve_path = '/uploads';
  
php
  CrudConfig::$upload_max_image_size = '12MB';
  
php
  CrudConfig::$upload_max_file_size = 50 * 1024 * 1024;
  
php
  $maxBytes = CrudConfig::getUploadMaxImageSize();
  
php
  $maxBytes = CrudConfig::getUploadMaxFileSize();
  
php
  CrudConfig::$images_in_grid = false; // Hide images in grid
  
php
  CrudConfig::$images_in_grid_height = 80; // Larger thumbnails
  
php
  CrudConfig::$bools_in_grid = false; // Show as text instead
  
php
  CrudConfig::$enable_select2 = true; // Use Select2 by default
  
php
  CrudConfig::$enable_filters = true; // Enable filters globally
  
php
  CrudConfig::$hide_table_title = true; // Remove table titles globally
  
php
  $crud->style('add_button_class', 'btn btn-sm btn-primary');
  
php
  $crud->theme([
      'styles' => ['toolbar_action_button_global_class' => 'btn btn-sm btn-outline-dark'],
      'texts' => ['filters' => 'Advanced filters'],
  ]);
  
php
  CrudStyle::$texts = [
      'add' => 'New',
      'save_changes' => 'Save',
      'no_records' => 'Nothing found.',
  ];
  
php
  $pdo = DB::connection();
  
php
  DB::setConnection($testPdo);
  
php
  DB::disconnect();
  
php
  $errors = $exception->getErrors();