Repeatable fields
Hello, I would like to create a package similar to this one, https://github.com/fourstacks/nova-repeatable-fields, but that goes to save the "repetable" fields in another table. Every time I save, it gives me an error saying that the attribute of the resource does not exist. How can I create a field that is not a resource attribute?
@cerelli Can you give us more details and the code you have currently?
You're going to need to modify or create your own field, nova-repeatable-fields won't do what you want.
I modify the nova-repeatable-fields. This field return a json in fillAttributeFromRequest. I have a lead resource and in in lead model:
public function notes()
{
return $this->hasMany('App\Note');
}
This is my test in fillAttributeFromRequest of repeator.
protected function fillAttributeFromRequest(NovaRequest $request,
$requestAttribute,
$model,
$attribute)
{
$class = get_class($model);
$arr = json_decode($request[$requestAttribute], true);
$notes = new \App\Note;
$notes->fill($arr);
dd($class, $requestAttribute, $arr, $notes);
if ($request->exists($requestAttribute)) {
$notes = [
['title' => 'Titolo 1','user_id' => 1,'priority' => 'Medium','body'=>'aa'],
['title' => 'Titolo 2','user_id' => 1,'priority' => 'Low','body'=>'bbbbb']
];
$model->$requestAttribute()->createMany($request[$requestAttribute]);
// $model->{$attribute} = json_decode($request[$requestAttribute]);
// dump($model->{$attribute} );
}
}
How can i save hasMany relation ? json_decode($request[$requestAttribute], true);