Fields

Introduction

Fields represent the type and characteristics of your stream data. For example a "name" field would likely be a string field type.

Fields are strictly concerned with data. Please see the UI package for configuring field inputs.

Defining Fields

Fields can be defined within the JSON configuration for your streams. You can get started by simply defining fields by handle and their type respectively.

// streams/contacts.json
{
    "fields": {
        "name": "string",
    }
}

To define more information about the field use an array:

// streams/contacts.json
{
    "fields": {
        "name": {
            "type": "string",
            "name": "fields.name"
        },
    }
}

Field Validation

Define rules and validators for fields to merge them with other stream validation.

// streams/contacts.json
{
    "rules": {
        "name": [
            "required",
            "max:100"
        ],
        "email": [
            "required",
            "email:rfc,dns"
        ],
        "company": "required|unique"
    }
}

Field Types

The field type is responsible for validating and casting its specific data type.

String

The string field type stores a string value. Other string-like fields may extend the string type.

{
    "type": "string"
}

URL

The url field type stores a URL or named route.

{
    "type": "url"
}

Hash

The hash field type stores a one-way hashed string, great for passwords.

{
    "type": "hash",
    "config": {
        "prefix": "string"
    }
}

Encrypted

The encrypted field type stores a two-way encrypted string.

{
    "type": "encrypted"
}

Markdown

The markdown field type stores markdown formatted text.

{
    "type": "markdown"
}

Select

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

{
    "type": "select",
    "config": {
        "options": {
            "first": "First Option",
            "second": "Second Option"
        }
    }
}

Callable Options

Besides basic array and associated arrays, you may specify a callable:

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

The $fieldType can then be injected in order to set the config.options manually:

// app/CustomOptions.php
class CustomOptions
{
    public function handle($fieldType)
    {
        $fieldType->config['options'] = [
            // Your options
        ];
    }
}

Array

The array field type stores array values.

{
    "type": "array",
    "config": {
        "format": "json" // json|yaml
    }
}

Multiselect

The multiselect field type stores an array of selections from a list of options. The multiselect field type also supports callable options.

{
    "type": "multiselect",
    "config": {
        "options": {
            "first": "First Option",
            "second": "Second Option",
            "third": "Third Option"
        }
    }
}

Boolean

{
    "type": "boolean"
}

Integer

{
    "type": "integer"
}

Datetime

{
    "type": "datetime"
}

Date

{
    "type": "date"
}

Time

{
    "type": "time"
}

Entry

{
    "type": "entry",
    "config": {
        "stream": "handle"
    }
}

Entries

{
    "type": "entries",
    "config": {
        "stream": "handle"
    }
}

Polymorphic

Relationship

{
    "type": "relationship",
    "config": {
        "related": "stream"
    }
}

Multiple

{
    "type": "multiple",
    "config": {
        "related": "stream"
    }
}

File

{
    "type": "file",
    "config": {
        "path": "storage/app/public/uploads"
    }
}

Image

{
    "type": "image",
    "config": {
        "path": "storage/app/public/uploads/img"
    }
}

Collection

Template