Skip to content

Form Fields, Layouts & Validation ​

Define rich create/edit forms — including 2-column layouts, grouped card sections, conditional visibility, helper text, auto-handled images/files, and async searchable selects — directly in resourceConfig()['fields'].

All 22 Supported Field Types ​

TypeRendered InputHighlights
text, email, password, numberStandard <Input />password ignored when empty on update
textarea<Textarea rows={4} />Plain multi-line input
rich-textZero-dependency Markdown toolbar + Live PreviewBold, Italic, Heading, Lists, Link, Code + safe preview toggle
selectSearchable Combobox (Command)Supports multiple, lazy Closure options, and signed async relationship search
radioResponsive 2-col radio cardsUses options
checkbox / toggleCard-styled <Checkbox />Safe boolean coercion + placeholder subtitle
date / datetimeNative date / datetime-local inputsTimezone-safe formatting & formatDateTimeLocal()
fileAuto-handled file input with existing file cardSupports disk, directory, path_column, delete_old, Download, Replace, Remove
imageAuto-handled image uploader with live thumbnail previewDefaults to accept="image/*", live URL.createObjectURL preview, Replace, Remove
chunked-fileDrag-and-drop chunked uploader (/crud/chunk-upload)See Chunked File Uploads
slugMonospace slug input with auto-sync & Regenerate buttonSet 'slug_from' => 'title' to auto-slugify while typing
tagsInteractive chip/tag inputPress Enter or comma to add; Backspace / × to remove
colorSynchronized color swatch + hex inputStores #rrggbb
key-valueDynamic key/value row editorStores associative JSON object
options-builderDynamic choice list + correct-index toggleIdeal for quizzes & polls
repeaterNested sub-form rowsRecursive validation rules (key.*.subkey)
hiddenNot renderedPreserved in form payload

Sections, 2-Column Grid, Help Text & Conditional Visibility ​

php
'form_columns'  => 2,
'form_sections' => [
    'Basic'   => ['title' => 'Basic Information', 'description' => 'Core identity and classification.', 'columns' => 2],
    'Media'   => ['title' => 'Media & Files', 'columns' => 1],
    'Content' => ['title' => 'Article Content', 'columns' => 1],
],
'fields' => [
    [
        'key'      => 'title',
        'label'    => 'Title',
        'type'     => 'text',
        'rules'    => 'required|string|max:255',
        'required' => true,
        'section'  => 'Basic',
        'help'     => 'Displayed on the public landing page.',
    ],
    [
        'key'       => 'slug',
        'label'     => 'URL Slug',
        'type'      => 'slug',
        'slug_from' => 'title',
        'rules'     => 'required|string|unique:articles,slug,{id}',
        'section'   => 'Basic',
    ],
    [
        'key'          => 'external_url',
        'label'        => 'External Link',
        'type'         => 'text',
        'rules'        => 'nullable|url',
        'section'      => 'Basic',
        'col_span'     => 2,
        'visible_when' => ['field' => 'source_type', 'equals' => 'external'],
    ],
    [
        'key'      => 'body',
        'label'    => 'Article Body',
        'type'     => 'rich-text',
        'rules'    => 'nullable|string',
        'section'  => 'Content',
        'col_span' => 2,
    ],
],

Supported visible_when Operators ​

equals, not_equals, in, not_in, truthy, falsy, empty, not_empty.


Auto-Handled file & image Fields ​

Standard file and image fields support the same zero-boilerplate storage options as chunked-file:

php
[
    'key'               => 'logo',
    'label'             => 'University Logo',
    'type'              => 'image',
    'rules'             => 'nullable|image|max:3072',
    'disk'              => 'public',
    'directory'         => 'universities',
    'path_column'       => 'logo_path',
    'delete_old'        => true,
]
  • On create/update, FileUploadService stores the file, deletes replaced files, and populates path_column (plus optional name_column & size_column).
  • Supports the same storage options as chunked-file: disk, directory (string|Closure), filename (Closure), preserve_filename, visibility, path_column, name_column, size_column, url_column, delete_old, and auto_handle.
  • On edit, FormField shows the existing image thumbnail (or file download card) with Replace and Remove ({ removed: true }).
  • Legacy controllers using 'ignore_on_save' => true (or 'auto_handle' => false) keep full manual control in beforeSave().

Repeater & Options-Builder Fields ​

php
[
    'key'                => 'variants',
    'label'              => 'Product Variants',
    'type'               => 'repeater',
    'rules'              => 'nullable|array',
    'hide_add_button'    => false,
    'hide_remove_button' => false,
    'fields'             => [
        ['key' => 'sku',   'label' => 'SKU',   'type' => 'text',   'rules' => 'required|string'],
        ['key' => 'price', 'label' => 'Price', 'type' => 'number', 'rules' => 'required|numeric|min:0'],
    ],
]
php
[
    'key'   => 'choices',
    'label' => 'Answer Options',
    'type'  => 'options-builder',
    'rules' => 'required|array|min:2',
]

Repeater fields are validated recursively (variants.*.sku, variants.*.price) and skipped in fillModel() so you can sync them cleanly inside afterSave().


Field Options Reference ​

KeyTypeDescription
key / label / typestringAttribute name, display label, and field renderer type
rules / rules_updatestring|arrayLaravel validation rules (supports Rule objects and {id} unique exclusion)
required / optional_on_updateboolMarks field required in UI; optional_on_update converts required → sometimes on edit
placeholder / helpstringInput placeholder and helper text shown below the input
section / col_spanstring / 1|2Groups field into a form_sections card and spans 1 or 2 grid columns
visible_whenarrayConditional display rule (field + operator: equals, not_equals, in, not_in, truthy, falsy, empty, not_empty)
optionsarray|ClosureStatic or lazy Closure options for select and radio ([['label' => ..., 'value' => ...]] or ['val' => 'Label'])
relationshiparrayDeclarative Eloquent options (model, value, label, search_columns, order_by, order_dir, limit, query Closure, async, endpoint)
multipleboolMulti-select combobox for select fields
slug_fromstringSource field key auto-slugified into a slug input
default / disabledmixed / boolInitial create value and disabled input flag
hide_on_create / hide_on_edit / hiddenboolVisibility control by form mode
ignore_on_saveboolSkip assigning this key in CrudService::fillModel()
accept, disk, directory, filename, preserve_filename, visibility, delete_old, path_column, name_column, size_column, url_column, auto_handlevariousStorage and column-mapping options for file, image, and chunked-file fields
fields / hide_add_button / hide_remove_buttonarray / boolNested field schema and controls for repeater fields

Lazy Options & Async Relationship Selects ​

Avoid running heavy queries on every controller request by using lazy closures or declarative async relationships:

php
[
    'key'     => 'category_id',
    'label'   => 'Category',
    'type'    => 'select',
    'rules'   => 'required|exists:categories,id',
    'options' => fn () => \App\Models\Category::orderBy('name')->pluck('name', 'id')->toArray(),
]
php
[
    'key'          => 'university_id',
    'label'        => 'University',
    'type'         => 'select',
    'rules'        => 'required|exists:universities,id',
    'relationship' => [
        'model'          => \App\Models\University::class,
        'value'          => 'id',
        'label'          => 'name',
        'search_columns' => ['name', 'short_code'],
        'limit'          => 25,
        'async'          => true, // Uses signed native GET /crud/options endpoint
    ],
]

When 'async' => true, OptionsService encrypts the approved model/columns into a user-scoped options_config token so the native GET /crud/options endpoint safely searches large tables with debounced queries and pre-hydrates selected labels on edit.

For non-async relationships ('async' => false, the default), you can also pass 'query' => fn ($q) => $q->where('is_active', true) along with 'order_by', 'order_dir', and 'limit' to scope the eager option list.

Released under the MIT License.