Closed jfdialogs closed 1 year ago
This is what I got to work, passing null
as the key. Seems to work.
Flexible::make('Education', 'education')
->addLayout('School Graduation', 'graduation', [
Text::make('School', 'school'),
Select::make('Graduated', 'graduated')
->options(array_reverse(range(1920, date('Y'))))
])
->button('Add School Graduation')
->confirmRemove('Remove school graduation?')
->resolver(new class() implements ResolverInterface {
public function get($resource, $attribute, $layouts) {
$items = collect($resource[$attribute] ?: []);
return $items->map(fn($item) => ($layout = $layouts->find('graduation'))
? $layout->duplicateAndHydrate(null, $item)
: null
)->filter();
}
public function set($model, $attribute, $groups)
{
return $model->$attribute = $groups
->map(fn($group) => $group->getAttributes());
}
}),
We are implementing several fields which are lists of objects, like this:
To do so, we need to not hold onto the generated flexible content blocks, e.g. approximately
Above, we would only store the attributes at rest.
I can do this somewhat on the model hydrate:
What I don't know is:
Is this possible/advisable?