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.
A select filled with the records of another admin model is a relation field.

Options

The options parameter lists values separated by commas. The label is also the stored value, so a label cannot contain a comma or a |.
In array notation options may be any array. Keys are stored, values are displayed.
An array with keys 0, 1, 2… is treated as a plain list, so [0 => 'No', 1 => 'Yes'] stores No and Yes. Start keys from 1 or use string keys.
A list of rows with an 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
For a field whose key ends with _id, the options may be returned under the key without the suffix (category_idcategory).

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
Options can be extended by 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.
Read the label of a stored value with getSelectOption(), or the label of any option key with getOptionValue():
Options of a select can also be hidden from a custom component, see filtering options.

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, required rejects an empty selection.
  • max:3 limits the number of selected values in the form.
  • multiple is supported by select, file, date and time fields. 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.
The template is applied in the form select and in the table.

Enum column

enum creates a MySQL enum column from the option keys instead of varchar.
Adding an option changes the column on the next 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.
It wins over 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.
The check runs only in the browser and only for loaded rows. Add a unique rule for a database guarantee.