Level 2
I needed something similar, so this is how you can try to do it:
Inside the Panel code:
new Panel('Read More Section', [
Text::make('Title')->rules(['max:255'])
->resolveUsing(function($value, $resource, $attribute) use($request) {
return Arr::get($resource->read_more_section, 'title');
}),
......
]),
Then you can create a hidden field corresponding to the column name, and use the fields to fill in the data via fillUsing method:
Hidden::make('Read More Section')->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'label' => $request->input('label'),
'link' => $request->input('link'),
];
$model->{$attribute} = $data;
})
You also need to add this method to your Nova Resource:
protected static function fillFields(NovaRequest $request, $model, $fields)
{
$fillFields = parent::fillFields($request, $model, $fields);
// first element should be model object
$modelObject = $fillFields[0];
// remove all attributes do not have relevant columns in model table
unset($modelObject->title);
unset($modelObject->description);
unset($modelObject->label);
unset($modelObject->link);
return $fillFields;
}
1 like