Select and radio fields
select renders a select and radio renders radio buttons. Both store the key of the selected option in a varchar(255) column.
Options
Theoptions parameter lists values separated by commas. The label is also the stored value, so a label cannot contain a comma or a |.
id column is keyed by id:
Options from the model
Options can also come from the$options property, or from the options() method for values loaded at runtime. Both are keyed by the field key and win over the options parameter of the field. A collection is converted automatically.
app/Models/Payment.php
_id, the options may be returned under the key without the suffix (category_id → category).
Options depending on the parent record
When the table is opened inside a parent record,options($row) receives the parent record. The edited record is not passed, options are loaded once for the whole table.
app/Models/OrdersItem.php
setOptionsProperty() of the model or of a module:
Options from
$options and options() are loaded only when the admin table is opened, not on every request.
The submitted value is not validated against the options, add an in: rule when it has to be.getSelectOption(), or the label of any option key with getOptionValue():
Multiple values
multiple allows selecting several values, stored as a JSON array in a json column and cast to a collection.
- When the user removes all values an empty array is stored,
requiredrejects an empty selection. max:3limits the number of selected values in the form.multipleis supported byselect,file,dateandtimefields. Other types get a JSON column too, but no cast and no form support.
Option label template
When option values are rows,option defines how an option is displayed. Use :column placeholders, or a single column name.
Enum column
enum creates a MySQL enum column from the option keys instead of varchar.
php artisan admin:migrate.
enum is ignored for multiple selects, which always use a JSON column.
Preselected option
defaultByOption preselects an option in the create form. Use an option key, or a column and a value to preselect the first related record matching them.
default. The column must be a real (not imaginary) field of the related model.
Unique options
unique_options hides options already used by other records displayed in the table, for example to assign every course only once.
unique rule for a database guarantee.