Select#

Select holds a choice among fixed options, select in the descriptor: one of a fixed set of options, or several with multiple():

Select::make('status')->of(OrderStatus::class),                    // a backed enum's cases
Select::make('size')->options(['s' => 'Small', 'm' => 'Medium']),  // value => label
Select::make('region')->options(fn () => Regions::all()),          // run once, when the resource compiles
Select::make('channels')->options(['web' => 'Web', 'retail' => 'Retail'])->multiple()->filterable(),
A Select field on the product form: a select labelled Status, showing Active
A Select field on the product form: a select labelled Status, showing Active
  • Options come from an array of value => label, a closure returning one (called when the resource compiles, never per request), or a backed enum, labelled from its case names. labels([...]) renames options and colors([...]) gives each a colour. A select on a backed enum property with no options of its own offers the enum’s cases; derivation makes one for every enum property.

  • searchable() gives the input a search box over the options, for a long list. Unlike other fields, it does not make the list’s search match the column.

  • badge([value => colour]) shows the values as coloured chips in lists and on the record. Without it, a value shows as its label, as a chip when its option has a colour.

  • multiple() holds several options. They are stored as a JSON list of option values, without duplicates, in the order the options are declared, whatever order the input sent them in.

Storage#

The property must match the mode; the build refuses a mismatch and converts nothing.

Mode

Property

Column

Single

string, int, or a backed enum

VARCHAR, an integer, or the enum’s backing type

Multiple

array or ?array

JSON on MySQL and MariaDB, jsonb on PostgreSQL

A single select on a string property stores every option value as text (404 => 'Not found' is "404"); on an int property every option value must be an integer; on an enum property every option must be one of its cases, and the entity receives the case. A multiple select stores the option values as declared (an int-backed enum’s as numbers). An empty list is null where the property allows it.

A multiple select is never sortable, grouped, summarized or edited in a list cell; the build refuses each. Its default() is a list of option values.

Strict options#

A value outside the options is refused on write: invalid_choice on the field, and for a multiple select on the offending value’s index (channels/1). A JSON body must send an option’s own type: 2, not "2", for an int option. A stored value outside the options throws Kinetis\Vector\Exception\StoredValueException on read rather than vanishing from the record. Removing an option therefore needs a data migration first: rewrite or clear the rows that still hold it, then remove it from the field.

Filters#

A single select filters with eq ne in nin, like any value. A multiple select filters with any (holding at least one of the listed options, the default) and all (holding every one of them), over a comma-separated list of option values:

GET /vector/r/products?filter[channels][any]=web,retail
GET /vector/r/products?filter[channels][all]=web,retail
GET /vector/r/products?filter[channels]=web        # a bare value is "any"

A nullable one adds null and nnull. The SQL is written per dialect with every value bound: JSON_CONTAINS on MySQL and MariaDB, ?| and @> on PostgreSQL’s jsonb. An index can help on PostgreSQL (CREATE INDEX ... USING GIN (channels)); on MySQL a multi-valued index over the column can.

A CSV import reads a multiple select’s cell as the JSON list an export writes (["web","retail"]) or as values separated by |.

It takes the common modifiers too.