Closed julianlaibach closed 2 years ago
Thank you for the sponsorship and nice words!
You should define your layouts before you call the resolve method on the flexible field. It tries to create layout instances when you call the resolve
method, but looking at your code, you have not defined them yet.
Thank you!
When i do the following:
public function flexible(Request $request)
{
$someModel = SomeModel::find($request->id);
$flexible = new Flexible('somecontent');
$flexible->addLayout('Content Section', 'test', [
Text::make('Title')
])
->make('Test', 'content');
$flexible->resolve($someModel);
return $flexible;
}
I now get the available Layouts and i can create the Field like that but if the $someModel already have Fields filled they are not returned so i cannot show the current Values from the Model. I hope you can understand my Problem...
Best Julian
Sorry... was my fault. I now got it working, passed the wrong Parameter to new Flexible()
So for everyone experiencing the same Issue here is my complete Code:
public function flexible(Request $request)
{
$someModel = SomeModel::find($request->id);
$flexible = new Flexible('content'); <- The Name in Database for the JSON Flexible Content ($attribute)
$flexible->addLayout('Content Section', 'test', [
Text::make('Title')
])
->make('Test');
$flexible->resolve($someModel);
return $flexible;
}
I have one last Problem... This i how i save the Values:
public function save(Request $request)
{
$someModel = SomeModel::find($request->id);
$someModel->content = json_encode($request->field);
$someModel->save();
return $someModel;
}
Everything is stored correctly in the Database and the Payload looks exactly like it should:
[
{
"key": "n8ZXCMbRdGBjOd80",
"layout": "test",
"attributes": {
"0": {
"name": "Title",
"panel": null,
"value": "Überschrift 1",
"stacked": false,
"helpText": null,
"nullable": false,
"readonly": false,
"required": false,
"sortable": false,
"attribute": "n8ZXCMbRdGBjOd80__title",
"component": "text-field",
"indexName": "Title",
"textAlign": "left",
"validationKey": "n8ZXCMbRdGBjOd80__title",
"sortableUriKey": "title",
"prefixComponent": true
},
"title": "afdsfasdf"
}
},
]
If i reload the Page it does not show any value, does there some kind of validation takes place? If i store the Values from the normal Nova Form everything works fine!
Thank you in advance! Best Julian
Hey there, thank you for this awesome Project! For a custom Nova Tool i need to create the Flexible Field PHP side and than pass it to the Frontend (api), my current approach is as follows:
I try to pass the original Modal to the flexibles resolve function and than adding the Layouts to return a complete Flexible Field back to the Frontend to display the Component but i just get the following Error:
Call to a member function find() on null {"userId":"***","exception":"[object] (Error(code: 0): Call to a member function find() on null at /var/www/html/vendor/whitecube/nova-flexible-content/src/Value/Resolver.php:43)
I'm not sure if my whole implementation is wrong but it would be great if we can get this running!
Thank you Julian