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

  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('Admin') ->field('is_admin') ->type(ResourceInputTypeEnum::PASSWORD) ->confirmed() ->addValidationRules( 'required', ), ) ); ...

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') ->type(ResourceInputTypeEnum::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 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,

  • SELECT,

  • DATE,

  • DATETIME,

  • TIME,

  • WEEK,

  • MONTH,

  • IMAGE,

  • HIDDEN,

  • PASSWORD, // but useless for exiting record...

  • RANGE,

  • PHONE/TEL,

  • COLOR (colorpicker),

  • TEXT/TEXTAREA (multiline text),

  • EDITOR/CKEDITOR/WYSIWYG (advanced text editor)

  • JSON (advanced JSON viewer)

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

value('param:1')

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 for password confirmation working automatically.

confirmed()

Optional

addValidationRules

Adding validation rules for current field.

Validation for password confirmation working automatically.

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') ->type(ResourceInputTypeEnum::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: 03 August 2025