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']);
});
}
}
Thank you for considering this.