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. The difference is that NewResource creates a record, while Resource edits an existing record.
NewResource configuration
Add a named NewResourceModule to an AdminixPage. This complete provider creates a user with connection-neutral validation based on the Eloquent model.
Result: /adminix/users-create renders a create form. The module name is required and must be unique within the page.
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 the 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 a field in the 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. multiple() is supported too: selected chips are restored from old input, submitted values are backend-validated against the async source, and the created record receives a JSON array string.
ResourceField::upload() is supported for create forms too. Use ResourceInputTypeEnum::FILE for stored files, or an IMAGE field with upload(...) for stored images. Dropzone uploads show configured accepted formats and maximum size inside the drop area. 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::password() is supported for create forms. 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.
Create forms honor ResourceField::visibleOnCreate()/hiddenOnCreate(). Hidden-on-create fields are not rendered and are excluded from server-side writable field resolution.
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:0')
| Optional | ||||||||
confirmed | Can be used only for fields with type Validation uses Laravel's
confirmed()
| Optional | ||||||||
addValidationRules | Adding validation rules for current field. Password confirmation uses Laravel's 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
Rendered example:
