FilamentF
Filament2y ago
hxn

repeater simple vs schema

Hello,

In my model, I have a field named attachments, which is cast as an array. The field can contain multiple path and looks like this:
attachments: "["ticket-attachments\/1715956812\/3v55MYasX2RhfVRoeoaSzdXtzwn9tNKZeNK5vYQz.png","ticket-attachments\/1715956812\/C5Y4cfy3fyiv8XVt7BfKxAXtuztJeWHSDR1GxtcQ.png","ticket-attachments\/1715956812\/suaEW2fieaxAYwONhDn9Oqeo81IWAU4voxEsFr5i.png"]"


When I use a simple repeater with a ViewField, the $getState() function returns the string path of my images as expected:
Repeater::make('attachments')
    ->simple(
        ViewField::make('attachments')
            ->view('filament.ticket-attachment'),
    )


However, when I switch from simple to schema, the $getState() function always returns null:
Repeater::make('attachments')
    ->schema([
        ViewField::make('attachments')
            ->view('filament.ticket-attachment'),
    ])


Here's the custom view:
<div>
    <img class="w-full p-8 mb-4" src="{{ asset('storage/' . $getState()) }}" alt="Attachment">
</div>


By switching to schema, I'm encountering an issue where the state is not being retrieved correctly. Any guidance on resolving this would be greatly appreciated.
Solution
Because simple returns a flat array, and non-simple returns an array containing the fields. So for non-simple the structure should be

[
  {'attachments': ...},
]
Was this page helpful?