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:

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

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

Decorator Usage

The decorated value provides collection access to the data.

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

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
@if($entry->items->isNotEmpty())
@foreach ($entry->items as $item)
// 
@endforeach
@endif

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