Array Type

Overview

The array field type is used for storing indexed arrays. Items can be simple or complex types. By default, any item type is valid.

// streams/example.json
"fields": {
    "items": {
        "type": "array"
    }
}

Data Structure

{
    "items": [
        "John Doe",
        "Jane Smith"
    ]
}

Basic array access:

@verbatim// Array access
{{ $entry->items[0] }}

@foreach ($entry->items as $index => $value)
{{ $index }}: {{ $value }}
@endforeach
@endverbatim

Decorator Usage

The decorated value provides collection access to the data.

@verbatim// Decorated value
{{ $entry->decorate('items')->implode(', ') }}
@endverbatim

Configuration

Wrapper

The array can optionally be wrapped with a generic collection or arrayable classname automatically when accessing the field.

{
// streams/example.json
"fields": {
    "items": {
        "type": "array",
        "config": {
            "wrapper": "array|collection|App\\MyCollection"
        }
    }
}
// welcome.blade.php
@verbatim@if($entry->items->isNotEmpty())
@foreach ($entry->items as $item)
// 
@endforeach
@endif
@endverbatim

Items

Use the items configuration to specify the allowed item types using field configurations. If specified, each item must be valid against any of the provided types.

// streams/example.json
"fields": {
    "items": {
        "type": "array",
        "config": {
            "wrapper": "array|collection|App\\MyCollection",
            "items": [
                { "type": "integer" },
                { "type": "string" },
                {
                    "type": "object",
                    "config": {
                        "schemas": [
                            { "stream": "addresses" }
                        ]
                    }
                },
            ]
        }
    }
}