Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 953 Bytes

select.mdx

File metadata and controls

60 lines (43 loc) · 953 Bytes

Select

A dropdown select (single value). For several values use Field::checkbox().


PHP API

Field::select(string $key): SelectField

Type-specific methods

->options(array $options): static

Associative array of value => label. Required.


Storage

  • "active" (string)

Example

Field::select('status')
    ->label('Status')
    ->options([
        'draft'    => 'Draft',
        'active'   => 'Active',
        'archived' => 'Archived',
    ])
    ->default('draft')
    ->setIndex(true)
    ->adminColumn(true)
    ->quickEdit(true),

Template usage

{{ ctrlfield_get('status') }}  {{-- returns 'active' --}}

To display the label instead of the value, use the options array:

@php
    $options = ['draft' => 'Draft', 'active' => 'Active', 'archived' => 'Archived'];
    $value   = ctrlfield_get('status');
@endphp
{{ $options[$value] ?? $value }}