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.

Basic Example

// streams/contacts.json
{
    "fields": [
        {
            "handle": "title",
            "type": "string"
        }
    ]
}

Full Example

To define more information about the field use an array:

// streams/contacts.json
{
    "fields": [
        {
            "handle": "title",
            "name": "Title",
            "description": "The title of the film.",
            "type": "string",
            "rules": ["min:4"],
            "config": {
                "default": "Untitled"
            },
            "example": "Star Wars: The Force Awakens"
        }
    ]
}

Field Validation

Define Laravel validation rules for fields and they will be merged the stream validation rules.

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

Field Types

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

Relationship

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

Multiple

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

File

{
    "type": "file",
    "config": {
        "path": "storage::uploads"
    }
}

Image

{
    "type": "image",
    "config": {
        "path": "storage::uploads.img"
    }
}