The set() method of the Repeater fields' JSON preset works fine if the Repeater is pointed to a nested element of a model's json / array attribute, e.g. Repeater::make('Nested Items', 'json_attribute->items'). The get() method, however, does not.
I create my own preset to override the get() method as follows, and it all appears to work well. Perhaps this could be folded into Nova to give Repeater fields a bit more flexibility?
class NestedJSON extends JSON
{
public function get(NovaRequest $request, Model $model, string $attribute, RepeatableCollection $repeatables)
{
return RepeatableCollection::make(
data_get($model, Str::replace('->', '.', $attribute)) // as opposed to $model->{$attribute}
)
->map(function ($block) use ($repeatables) {
return $repeatables->newRepeatableByKey($block['type'], $block['fields']);
});
}
}
Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)
The set() method of the Repeater fields' JSON preset works fine if the Repeater is pointed to a nested element of a model's json / array attribute, e.g.
Repeater::make('Nested Items', 'json_attribute->items')
. The get() method, however, does not.I create my own preset to override the get() method as follows, and it all appears to work well. Perhaps this could be folded into Nova to give Repeater fields a bit more flexibility?
Thank you for considering this.