Introduction
Fields are a core part of an admin panel, that's why they are first-class citizens in Artificer.
In your fields.php config file yo can find:
- classmap
- types
Class Map
This is the point were you can add custom fields. Refer to Adding a field
Types
By default, Artificer tries to match the field type name with the column name.
However, in most cases, you will need something more complex than that. In this example we could match one of those column names:
<?php
...
'checkbox' => [
'autodetect' => [
'accept',
'active',
'boolean',
'activated',
'confirmed',
'you get the idea',
],
],
Sometimes you don't want to specify a name but you follow some convention. You can add regex when this happens:
<?php
...
'datetime' => [
// For example: 'created_at'
'regex' => [
'/_at$/',
'/_on$/',
],
...
],
Type detection in detail
Once one of the following checks is truthy that type is the selected one.
- Match in regex
- Type match (equal)
- Match in autodetect
- Type name similar
- Default type
Also you may want a type to have specific attributes:
<?php
...
'text' => [
"attributes" => [
'class' => 'form-control',
],
],
If you need to add behaviour to a field you can do it by using Field Widgets:
<?php
...
'date' => [
'autodetect' => [
'_at'
],
'widgets' => [
\Mascame\Artificer\Widgets\DateTimepicker::class,
]
],
If there was no type match, it will fallback to the default value:
<?php
...
'default' => [
'type' => 'text'
]
Updated less than a minute ago