© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
5 replies
Soundmit

Foreach error with repeater field

Hi, i have strange behaviour with a repeater field (never encountered before)
i have a simple repeater
Forms\Components\Repeater::make('links')
                    ->label('Links')   
                    ->maxItems(1)
                    ->addActionLabel('Add button')
                    ->schema([
                        Forms\Components\TextInput::make('url')
                            ->required()->url(),
                        Forms\Components\TextInput::make('text')
                            ->required(),
                    ]),
Forms\Components\Repeater::make('links')
                    ->label('Links')   
                    ->maxItems(1)
                    ->addActionLabel('Add button')
                    ->schema([
                        Forms\Components\TextInput::make('url')
                            ->required()->url(),
                        Forms\Components\TextInput::make('text')
                            ->required(),
                    ]),

when i create a new item, it works
when i try to edit an exhisting item, populated with a seeder
i have the error 'foreach() argument must be of type array|object, string given'

the field is a longtext field, with cast as array (but if i change cast to json is the same)
in the database, it saved like this (new from form)
[{"url":"https:\/\/www.google.com","text":"test"}]
[{"url":"https:\/\/www.google.com","text":"test"}]


while the seeder save like this
"[{\"url\":\"https:\\\/\\\/www.google.com\",\"text\":\"test\"}]"
"[{\"url\":\"https:\\\/\\\/www.google.com\",\"text\":\"test\"}]"
Solution
I would use an array in the seeder... you have the cast setup in your model?
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Update each repeater field 2 fields outside the repeater
FilamentFFilament / ❓┊help
2y ago
Dynamic Repeater Field
FilamentFFilament / ❓┊help
2y ago
Repeater unique field
FilamentFFilament / ❓┊help
3y ago