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",
            "protected": false
        }
    ]
}

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"]
        }
    ]
}

Basic Usage

Values are stored as an image source

Image::make($entry->profile_image)->url();

Field Decorators

Field decorators provide expanded function to entry attributes like a universal presenter.

The below example demonstrates the image field decorator:

$entry->decorate('profile_image')->url();

You may also use magic methods derived from "camel casing" the field's handle to invoke decoration.

$entry->profileImage()->url();

Field Types

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

@foreach (Streams::entries('docs_core')->where('category', 'field_types')->orderBy('sort', 'ASC')->orderBy('name', 'ASC')->get() as $entry)

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"
    }
}