Adminix Documentation Help

Modal new resource

Description

The "Modal new resource" module purpose - render a form to create a new record of some entity

Format is similar to New resource module. Difference — Modal new resource resource shows a form inside a modal without a page reload, New 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 newItemLink in ListModule

Relation managers also use ModalNewResourceModule for child create. In that flow Adminix signs the parent relation context and injects the relation foreign key as a server-owned hidden field, so browser-sent parent ids are ignored.

  1. Configuration

  2. Fields

  3. Validation

ModalResource configuration

To add to the page NewResource module you need paste AlexKudrya\Adminix\Modules\Resource\ModalNewResourceModule 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\ModalNewResourceModule; ... $page = new AdminixPage(); ... $page->addModule( ListModule::name('users_list') ... ->newItemLink( ModalTogglerModule::name('new_user_btn') ->title('New user') ->icon('bi bi-search') ->modalName('new_user_modal') ) ); $page->addModule( ModalNewResourceModule::name('new_user_modal') ->title('User') ->dataSource(User::class) ->addFields( ResourceField::name('Name') ->field('name') ->type(ResourceInputTypeEnum::STRING) ->required(), ResourceField::name('Email') ->field('email') ->type(ResourceInputTypeEnum::EMAIL) ->required() ->addValidationRules( 'email', 'unique:pgsql.users,email' ), ResourceField::name('Admin') ->field('is_admin') ->type(ResourceInputTypeEnum::BOOLEAN), ResourceField::name('Password') ->field('password') ->password() ->confirmed() ->addValidationRules( 'required', ), ) ); ...

Result: ResourceInputTypeEnum::BOOLEAN renders a switch in the modal create form. Modal submits normalize the checkbox request value to 1 for checked and 0 for unchecked, so Laravel boolean validation receives stable values instead of browser defaults such as on.

Modal create forms also support ResourceField::upload(). The modal submits multipart FormData, validates files through the server-side field configuration, stores them through Laravel Storage, and persists only the stored path. Invalid mime/size validation returns normal JSON field errors and does not store the uploaded file. See Resource for the full upload API and expected result.

ModalNewResource configuration methods

Method

Description

name

Name of module, must be unique in current page.

name('new_user_modal')

Required

title

Title on the top of module

title('NEW USER')

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

ModalTogglerModule configuration

To add to the page NewResource module you need paste AlexKudrya\Adminix\Modules\Resource\ModalNewResourceModule class instance as an argument to newItemLink 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\ModalNewResourceModule; use AlexKudrya\Adminix\Modules\InputSelectSrc; use AlexKudrya\Adminix\Modules\Resource\ResourceField; use AlexKudrya\Adminix\Modules\Resource\ResourceInputTypeEnum; $page = new AdminixPage(); $page->addModule( ModalNewResourceModule... ->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() ->required(), 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 ModalNewResourceModule object.

ResourceField::asyncSrc() is supported for modal create SELECT fields. The UI searches remote options through the package async endpoint and preserves the existing modal validation feedback behavior.

ResourceField::upload() is supported for modal create fields too. Use FILE for stored files and an IMAGE field with upload(...) for stored images; validation errors are returned through the existing modal field feedback blocks.

ResourceField::password() is supported for modal create fields. It renders password inputs with an optional visibility toggle and Laravel-compatible field_confirmation naming when confirmed() is enabled. updateOnly() password fields are ignored during creation; immutable() password fields can be created but are not writable on edit forms. See Resource for the full password contract and security notes.

Modal create fields honor both the modal and create visibility contexts. Use hiddenOnModal() to remove a field from every modal form, or hiddenOnCreate() when the field must be unavailable on all create 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 ModalNewResourceModule object

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

Way 1 example:

use AlexKudrya\Adminix\AdminixPage; use AlexKudrya\Adminix\Modules\Resource\ModalNewResourceModule; use AlexKudrya\Adminix\Modules\InputSelectSrc; use AlexKudrya\Adminix\Modules\Resource\ResourceField; use AlexKudrya\Adminix\Modules\Resource\ResourceInputTypeEnum; $page = new AdminixPage(); $page->addModule( ModalNewResourceModule... ->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\ModalNewResourceModule; $page = new AdminixPage(); $page->addModule( ModalNewResourceModule... ->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\ModalNewResourceModule; $page = new AdminixPage(); $page->addModule( ModalNewResourceModule... ->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', ], ]) ) ...
Last modified: 25 June 2026