The "Resource" module purpose - render a form to edit some exited record of some entity
Format is very similar to New resource module. Difference - Resource module is a form for working with exiting records, NewResource - is a form for creating new records.
Resource 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:
use App\Models\User;
use AlexKudrya\Adminix\Enums\ColorsEnum;
use AlexKudrya\Adminix\Modules\Resource\NewResourceModule;
...
$page = new AdminixPage();
...
$page->addModule(
NewResourceModule::title('NEW USER')
->title('NEW USER')
->dataSource(User::class)
->successRedirectUri(UsersPage::URI)
->addFields(...)
)
...
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
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:1' become to 341
An argument can be only AlexKudrya\Adminix\Modules\Resource\ResourceProperty
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.
All fields become not editable, render not inputs but just text
readonly()
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.
use AlexKudrya\Adminix\AdminixPage;
use AlexKudrya\Adminix\Modules\Resource\NewResourceModule;
use AlexKudrya\Adminix\Modules\InputSelectSrc;
use AlexKudrya\Adminix\Modules\Resource\ResourceField;
use AlexKudrya\Adminix\Modules\Resource\ResourceInputTypeEnum;
$page = new AdminixPage();
$page->addModule(
NewResourceModule...
->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 NewResourceModule 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)
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.
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.
Used only for fields with typeHIDDEN 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 typePASSWORD. 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.