Repeater and EditAction error

I have a list of items created from the Repeater Input and saved in DB as a json. When I used the edit action I get and error.
foreach() argument must be of type array|object, string given {"userId":1,"exception":"[object] (ErrorException(code: 0): foreach() argument must be of type array|object, string given at /var/www/html/vendor/filament/forms/src/Components/Repeater.php:783)

Below is how I try to

->beforeFormFilled(function (EditAction $action, Order $record) {
// Runs before the form fields are populated from the database.
// dd(gettype(json_decode($record['items'],true)));
$record['items'] = json_decode($record['items'], true);
})
dd(gettype(json_decode($record['items'])));
$record['items'] = json_decode($record['items'], true);
foreach() argument must be of type array|object, string given {"userId":1,"exception":"[object] (ErrorException(code: 0): foreach() argument must be of type array|object, string given at /var/www/html/vendor/filament/forms/src/Components/Repeater.php:783)

Below is how I try to

->beforeFormFilled(function (EditAction $action, Order $record) {
// Runs before the form fields are populated from the database.
// dd(gettype(json_decode($record['items'],true)));
$record['items'] = json_decode($record['items'], true);
})
dd(gettype(json_decode($record['items'])));
$record['items'] = json_decode($record['items'], true);
Solution:
Right, but a repeater, unless it is a relationship, needs to be cast on the model as either array or json.
Jump to solution
5 Replies
awcodes
awcodes5mo ago
What exactly are you trying to do? If all your casts are correct the repeater shouldn’t need any overrides.
KingNii
KingNiiOP5mo ago
I'm not using any cast. The column is set json @awcodes I have a list of items that is curated using the repeater. I'want to be able to save it and also edit it. Note that I'm only using the form builder but not the panel. @awcodes
Solution
awcodes
awcodes5mo ago
Right, but a repeater, unless it is a relationship, needs to be cast on the model as either array or json.
awcodes
awcodes5mo ago
If you cast it, then you want need any of this. Laravel will handle it.
KingNii
KingNiiOP5mo ago
@awcodes Thank you. Problem solved!!!
Want results from more Discord servers?
Add your server