New resource
Description
The "New Resource" module purpose - render a form to create a new record of some entity
Format is very similar to Resource module. Difference - NewResource - is a form for creating new records, Resource module is a form for working with exiting records.
NewResource configuration
To add to the page NewResource module you need paste AlexKudrya\Adminix\Modules\Resource\NewResourceModule class instance as an argument to addModule method of AdminixPage object.
Example:
NewResource configuration methods
Method | Description | |
|---|---|---|
name | Name of module, must be unique in current page.
name('new_user')
| Required |
title | Title on the top of module
title('NEW USER')
| Optional |
dataSource | Source of data for new entity creation, can be an
dataSource(\App\Models\User::class)
or
dataSource('users')
| Required |
addField addFields | Methods by which you can add fields for current Argument can be only
->addField(
ResourceField::name('Name')
->field('name')
->type(ResourceInputTypeEnum::STRING)
->required()
)
| Required |
addFieldValidation | Method by which you can add validation rules for field in current Format similar to native Laravel Validation feature. Details described below. #Validation
->addFieldValidation(
'name',
[
'string',
'required',
"unique:". User::class.",name"
]
)
| Optional |
successRedirectUri | An uri of adminix page, where user will be redirected in case of successful record creation.
successRedirectUri(UsersPage::URI)
| Optional |
Fields
Fields is an array, of input fields to be rendered in the Form.
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 NewResourceModule object.
ResourceField::asyncSrc() is supported for create-form SELECT fields. Use it the same way as in ResourceModule when a related table is too large for eager-loaded src() options. Old input after validation errors is kept as a temporary selected option and resolved by the async option endpoint when the page loads.
ResourceField::upload() is supported for create forms too. Use ResourceInputTypeEnum::FILE for stored files, or an IMAGE field with upload(...) for stored images. The created record receives the stored filesystem path after validation succeeds; uploaded files are not restored into old input after validation errors because browsers do not allow programmatic file input values. See Resource for the full upload example and result details.
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 Available types:
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 For example, Example:
ResourceField::name('Role')
->field('role_id')
->type(ResourceInputTypeEnum::SELECT)
->required()
->src(
InputSelectSrc::dataSource(Role::class)
->nameField('name')
->valueField('id')
),
| Optional | ||||||||
addSelectRecords | Required for fields with type Arguments can be only
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
value('some text')
Or you can paste parameter from route, if you provided it. For example
value('param:1')
| Optional | ||||||||
confirmed | Can be used only for fields with type 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.
There are 3 ways to add validation rules to your newResource form:
Add rules to every
ResourceFieldpersonally, by usingaddValidationRules()methodAdd rules to every field by using
addFieldValidation()method ofNewResourceModuleobjectAdd all rules for add fields by using
validation()method ofNewResourceModuleobject
Way 1 example:
Way 2 example:
Way 3 example:
Appearance examples
Example: New Record form from New User creation

Example: New Record form with validation errors
