Adminix Documentation Help

Modal resource

Description

The "Modal resource" module purpose - render a form to edit some exited record of some entity

Format is similar to Resource module. Difference — Modal resource resource shows a form inside a modal without a page reload, Resource — is a separate page and requires page reloading.

Important moment — to open modal you required clicking a special trigger — ModalTogglerModule, which can be added as an action in ListModule

Relation managers also use ModalResourceModule for child edit. In that flow Adminix signs the parent relation context, injects the child foreign-key criterion server-side, and returns a controlled not-found JSON response when the child record does not belong to the parent.

  1. Configuration

  2. Fields

  3. Validation

  4. Appearance examples

ModalResource configuration

To add to the page NewResource module you need paste AlexKudrya\Adminix\Modules\Resource\ModalResourceModule class instance as an argument to addModule method of AdminixPage object.

Example:

use App\Models\User; use AlexKudrya\Adminix\Enums\ColorsEnum; use AlexKudrya\Adminix\Modules\Resource\ModalResourceModule; ... $page = new AdminixPage(); ... $page->addModule( ListModule::name('users_list') ... ->addActions( ModalTogglerModule::name('open') ->title('Open') ->icon('bi bi-search') ->modalName('user_modal') ->params(['record:id']) ) ); $page->addModule( ModalResourceModule::name('user_modal') ->title('User') ->dataSource(User::class) ->addProp(ResourceProperty::key('id')->value('param:0')) ->addFields( ResourceField::name('Name') ->field('name') ->type(ResourceInputTypeEnum::STRING) ->readonly(), ResourceField::name('Email') ->field('email') ->type(ResourceInputTypeEnum::EMAIL) ->addValidationRules( 'email', 'unique:pgsql.users,email' ), ResourceField::name('Admin') ->field('is_admin') ->type(ResourceInputTypeEnum::BOOLEAN) ->addValidationRules( 'required', 'boolean', ), ResourceField::name('Registered') ->field('created_at') ->type(ResourceInputTypeEnum::DATETIME) ->readonly(), ) ); ...

Result: ResourceInputTypeEnum::BOOLEAN renders a switch in the modal edit form. When the modal loads data, Adminix treats stored true, 1, '1', 'true', and 'on' values as checked; when the modal saves, the browser request sends 1 for checked and 0 for unchecked, so Laravel boolean validation accepts both states.

Modal edit forms also support ResourceField::upload(). File inputs are never filled programmatically by JavaScript; Adminix renders a separate current-file/current-image preview after fetch-data and submits multipart FormData through the modal API. Validation errors are returned as normal field errors, and boolean checkbox normalization remains compatible with upload fields in the same modal. See Resource for the full upload API and storage semantics.

ModalResource configuration methods

Method

Description

name

Name of module, must be unique in current page.

name('user')

Required

title

Title on the top of module

title('USER')

Optional

addProp

addProps

An array of fields for properties in url to select the desired record from the database.

For example: The url is - https://domain.my/adminix/user/341, then 'param:0' become to 341. Legacy one-based providers that use 'param:1' for this value remain supported for compatibility, but new pages should use zero-based params.

An argument can be only AlexKudrya\Adminix\Modules\Resource\ResourceProperty

->addProp( ResourceProperty::key('id')->value('param:0') )

or

->addProps( ResourceProperty::key('id')->value('param:0'), ResourceProperty::key('is_admin')->value(false), )

Optional

dataSource

Source of data for new entity creation, can be an Eloquent Model, for example \App\Models\User::class or name of table in database users or public.users

dataSource(\App\Models\User::class)

or

dataSource('users')

Required

addField

addFields

Methods by which you can add fields for current NewRosurce module. Details described below. #Fields

Argument can be only AlexKudrya\Adminix\Modules\Resource\ResourceField class instance.

->addField( ResourceField::name('Name') ->field('name') ->type(ResourceInputTypeEnum::STRING) ->required() )

Required

addFieldValidation

Method by which you can add validation rules for field in current NewRosurce module.

Format similar to native Laravel Validation feature.

Details described below. #Validation

->addFieldValidation( 'name', [ 'string', 'required', "unique:". User::class.",name" ] )

Optional

readonly

All fields become not editable, render not inputs but just text

readonly()

Optional

ModalTogglerModule configuration

To add to the page NewResource module you need paste AlexKudrya\Adminix\Modules\Resource\ModalResourceModule class instance as an argument to addModule method of AdminixPage object.

Fields

Fields is an array, of input fields to be rendered in the Form.

use AlexKudrya\Adminix\AdminixPage; use AlexKudrya\Adminix\Modules\Resource\ModalResourceModule; use AlexKudrya\Adminix\Modules\InputSelectSrc; use AlexKudrya\Adminix\Modules\Resource\ResourceField; use AlexKudrya\Adminix\Modules\Resource\ResourceInputTypeEnum; $page = new AdminixPage(); $page->addModule( ModalResourceModule... ->addFields( ResourceField::name('Name') ->field('name') ->type(ResourceInputTypeEnum::STRING) ->required(), ResourceField::name('Email') ->field('email') ->type(ResourceInputTypeEnum::EMAIL) ->required(), ResourceField::name('Password') ->field('password') ->password() ->confirmed() ->updateOnly(), ResourceField::name('Role') ->field('role_id') ->type(ResourceInputTypeEnum::SELECT) ->required() ->src( InputSelectSrc::dataSource(Role::class) ->nameField('name') ->valueField('id') ), ResourceField::name('Admin') ->field('is_admin') ->type(ResourceInputTypeEnum::HIDDEN) ->value(false), ) ) ...

To add field to your NewResource module you need paste AlexKudrya\Adminix\Modules\Resource\ResourceField class instance as an argument to addField or addFields method of ModalResourceModule object.

ResourceField::asyncSrc() is supported for modal edit SELECT fields. The modal keeps using server-side module configuration: after fetch-data sets the stored value, Adminix resolves the selected label through the async option endpoint, including signed relation context when the modal belongs to a relation manager.

ResourceField::upload() is supported for modal edit fields too. Use FILE for stored files and an IMAGE field with upload(...) for stored images; the modal preview is display-only and the file input stays empty until the user chooses a replacement.

ResourceField::password() is supported for modal edit fields. Fetching modal data never returns the stored password value, optional blank password submissions are ignored on update, and confirmed() uses Laravel-compatible field_confirmation naming. Use updateOnly() for password-change modals and immutable() when the value must not be changed after creation. See Resource for the full password contract and security notes.

Modal edit fields honor both the modal and update visibility contexts. Use hiddenOnModal() to remove a field from every modal form, or hiddenOnUpdate() when the field must be unavailable on all edit surfaces. Hidden-by-context fields are not rendered and are excluded from the modal API writable whitelist.

ResourceField configuration

Method

Description

name

Title of the libel displayed near to the input

'name' => 'Email',

Required

type

Type of rendered input, can be provided only by AlexKudrya\Adminix\Modules\Resource\ResourceInputTypeEnum Enum class.

Available types:

  • STRING,

  • EMAIL,

  • INTEGER,

  • BOOLEAN,

  • FILE (stored upload),

  • SELECT,

  • DATE,

  • DATETIME,

  • TIME,

  • WEEK,

  • MONTH,

  • IMAGE (image URL/path input, or stored image upload when upload() is enabled),

  • HIDDEN,

  • PASSWORD,

  • RANGE,

  • PHONE/TEL,

  • COLOR (colorpicker),

  • TIMEZONE (IANA timezone select),

  • TEXT/TEXTAREA (multiline text),

  • EDITOR/CKEDITOR/WYSIWYG (advanced text editor)

  • JSON (JSON code textarea with safe fallback)

  • KEY_VALUE (JSON object editor with key/value rows)

  • TAGS (tag input with chip preview)

type(ResourceInputTypeEnum::EMAIL)

Required

field

Name of field in database table where new record will be created.

field('role_id')

Required

required

If enabled - field will be required for form submitting, and form wil not be submitted until this field wil not be filled. By default, is disabled.

required()

Optional

src

Required for filed with type SELECT if select_records is empty. Need to display correct <options/> of <select/>input.

For example, users table has related table roles, and relation maked by role_id field in users table. To dasplay select with options from roles table, you need to configure src correctly.

Example:

ResourceField::name('Role') ->field('role_id') ->type(ResourceInputTypeEnum::SELECT) ->required() ->src( InputSelectSrc::dataSource(Role::class) ->nameField('name') ->valueField('id') ),

setting

Description

dataSource

Source of data for filed items, can be an Eloquent Model - \App\Models\Role::class or name of table in database rolesor public.roles

nameField

Name of field which will be a label in <option/>

valueField

Name of field which will be a value in <option/> (usually it is "id")

Optional

addSelectRecords

Required for fields with type SELECT as an alternative for src(). Required if src() is empty. It is a list of options, where name() is a title of <option/>, and value()is a value of <option/>

Arguments can be only AlexKudrya\Adminix\Modules\SelectRecord class instances.

ResourceField::name('Role') ->field('role_id') ->type(ResourceInputTypeEnum::SELECT) ->addSelectRecords( SelectRecord::name('Admin')->value(1), SelectRecord::name('Manager')->value(2), SelectRecord::name('Seller')->value(3), SelectRecord::name('Guest')->value(4), )

Optional

value

Used only for fields with type HIDDEN and provides fixed value to it.

value('some text')

Or you can paste parameter from route, if you provided it. For example https://site.com/adminix/new_order/315, 315 in this case will be pasted as value into this hidden input. Use param:0 for the first route parameter in new pages; legacy param:1 remains supported for existing providers.

value('param:0')

Optional

confirmed

Can be used only for fields with type PASSWORD. Determines password confirmation and renders additional PASSWORD input below current for password confirmation.

Validation uses Laravel's field_confirmation request key.

confirmed()

Optional

addValidationRules

Adding validation rules for current field.

Password confirmation uses Laravel's field_confirmation request key.

Format similar to Laravel native Validation feature.

Details here Validation.

->addValidationRules( 'integer', 'required', 'exists:'. Role::class.',id' ),

Optional

Validation

An array of validation rules for form input data. Format similar to Laravel native Validation feature.

#Laravel Validation

There are 3 ways to add validation rules to your newResource form:

  • Add rules to every ResourceField personally, by using addValidationRules() method

  • Add rules to every field by using addFieldValidation() method of ModalResourceModule object

  • Add all rules for add fields by using validation() method of ModalResourceModule object

Way 1 example:

use AlexKudrya\Adminix\AdminixPage; use AlexKudrya\Adminix\Modules\Resource\ModalResourceModule; use AlexKudrya\Adminix\Modules\InputSelectSrc; use AlexKudrya\Adminix\Modules\Resource\ResourceField; use AlexKudrya\Adminix\Modules\Resource\ResourceInputTypeEnum; $page = new AdminixPage(); $page->addModule( ModalResourceModule... ->addFields( ResourceField::name('Name') ->field('name') ->type(ResourceInputTypeEnum::STRING) ->required() ->addValidationRules( 'string', 'required', "unique:". User::class.",name" ), ResourceField::name('Email') ->field('email') ->type(ResourceInputTypeEnum::EMAIL) ->required() ->addValidationRules( 'email', 'required', "unique:". User::class.",email" ), ResourceField::name('Password') ->field('password') ->password() ->confirmed() ->required() ->addValidationRules( 'string', 'required', 'confirmed' ), ResourceField::name('Role') ->field('role_id') ->type(ResourceInputTypeEnum::SELECT) ->required() ->src( InputSelectSrc::dataSource(Role::class) ->nameField('name') ->valueField('id') ) ->addValidationRules( 'integer', 'required', 'exists:'. Role::class.',id' ), ) ) ...

Way 2 example:

use AlexKudrya\Adminix\AdminixPage; use AlexKudrya\Adminix\Modules\Resource\ModalResourceModule; $page = new AdminixPage(); $page->addModule( ModalResourceModule... ->addFields(...) ->addFieldValidation('name', [ 'string', 'required', 'unique:App\Models\User,name', ]) ->addFieldValidation('email', [ 'email', 'required', 'unique:App\Models\User,email', ]) ->addFieldValidation('password', [ 'string', 'required', "confirmed", ]) ->addFieldValidation('role_id', [ 'integer', 'required', 'exists:App\Models\Role,id', ]) ) ...

Way 3 example:

use AlexKudrya\Adminix\AdminixPage; use AlexKudrya\Adminix\Modules\Resource\ModalResourceModule; $page = new AdminixPage(); $page->addModule( ModalResourceModule... ->addFields(...) ->validation([ 'name' => [ 'string', 'required', 'unique:App\Models\User,name', ], 'email' => [ 'email', 'required', 'unique:App\Models\User,email', ], 'password' => [ 'string', 'required', "confirmed", ], 'role_id' => [ 'integer', 'required', 'exists:App\Models\Role,id', ], ]) ) ...

Appearance examples

Example: User id = 1 Record form for edition

Last modified: 25 June 2026