Select Type

Overview

The select field type stores a selection from a list of options.

// streams/users.json
"fields": {
    "status": {
        "type": "select",
        "config": {
            "options": {
                "enabled": "Enabled",
                "pending": "Pending",
                "disabled": "Disabled"
            },
            "default": "pending"
        }
    }
}

Callable Options

Besides basic array and associated arrays, you may specify an invokable class:

{
    "type": "select",
    "config": {
        "options": "\\App\\InvokableOptions"
    }
}

Or, callable class and method:

{
    "type": "select",
    "config": {
        "options": "\\App\\[email protected]"
    }
}

The $type can be injected in order aid in returning options:

// app/InvokableOptions.php
class InvokableOptions
{
    public function __invoke($type)
    {
        return [
            'foo' => 'Bar',
        ];
    }
}

// app/CustomOptions.php
class CustomOptions
{
    public function handle($type)
    {
        return [
            'foo' => 'Bar',
        ];
    }
}

Data Structure

{
    "status": "enabled"
}

Basic value access displays the stored key value:

// Basic access
{{ $entry->status }}

Decorator Usage

Select types also provide decorated values.

// Decorated value
Status: {{ $entry->status()->value() }}

Methods

@todo Generate methods from @docs

Configuration

@todo Generate config options from class::configuration