whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
787 stars 234 forks source link

Unable to parse incoming Flexible content, data should be an array #360

Closed ZsarkZ closed 2 years ago

ZsarkZ commented 2 years ago

I have two models for example a model and a description model with a one to one relationship when i try to create model and description model at the same time i get this error, here is my code

` //main model public function fields(NovaRequest $request) { return [

        ID::make()->sortable(),
        Text::make('Name')->rules('required', 'max:255'),
        Slug::make('Slug')
            ->creationRules('unique:countries,slug')
            ->updateRules('unique:countries,slug,{{resourceId}}')
            ->onlyOnForms()
            ->from('Name'),
        Text::make('Local Name')->rules('required', 'max:255'),
        Text::make('Code')->rules('required', 'max:10'),
        Boolean::make('Visibility'),
        HasOne::make('Country Decription De', 'decriptionDe', \App\Nova\CountryDescriptionDe::class),
    ];
}

`

` // description model public function fields(NovaRequest $request) { return [

        ID::make()->sortable(),
        BelongsTo::make('Country'),
        Flexible::make('Content')
            ->addLayout('Content section', 'content', [
                Text::make('Title'),
                Markdown::make('Content')
            ]),
    ];
}

` 1656999450716

but if you create a model through the description model, then work well 1657000803307

toonvandenbos commented 2 years ago

Are you sure this problem is related to this package ? Could you provide the error you're encountering ? Thanks.

ZsarkZ commented 2 years ago

Are you sure this problem is related to this package ? Could you provide the error you're encountering ? Thanks.

exception: "Exception" file: "/home/sark/www/test/vendor/whitecube/nova-flexible-content/src/Flexible.php" line: 394 message: "Unable to parse incoming Flexible content, data should be an array."

I think the problem with HasOne nova field. if i used HasOne nova show two form for one time main form and hasone model form and i think that Flexible field don't understand what form it need

toonvandenbos commented 2 years ago

Indeed, it seems to me the HasOne field does not provide the correct data structure to the flexible field. Can you debug and dump what the field is receiving when used inside a HasOne field ?

ZsarkZ commented 2 years ago

Indeed, it seems to me the HasOne field does not provide the correct data structure to the flexible field. Can you debug and dump what the field is receiving when used inside a HasOne field ?

Form data looks like this

name: Zimbabwe slug: zimbabwe local_name: Zimbabwe code: ZW languages: currencies: payments: descriptionDe[name]: test descriptionDe[slug]: test descriptionDe[title]: descriptionDe[capital]: descriptionDe[population]: descriptionDe[area]: descriptionDe[_nova_flexible_content_fields]: ["content"] descriptionDe[content]: [{"layout":"flex_content","key":"BLT6mJ6rBHAjUsjX","attributes":{"BLT6mJ6rBHAjUsjX__top_description":"

test

","BLT6mJ6rBHAjUsjXbottom_description":""}}] descriptionDe[visibility]: 1

toonvandenbos commented 2 years ago

Alright, can you open your vendor files and add a dump/log after this line in order to get a glimpse of what the incoming request data looks like (the contents of $value) ?

ZsarkZ commented 2 years ago

Alright, can you open your vendor files and add a dump/log after this line in order to get a glimpse of what the incoming request data looks like (the contents of $value) ?

[2022-07-18 12:55:37] laravel.WARNING: Return type of Whitecube\NovaFlexibleContent\Layouts\Layout::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/sark/www/test/vendor/whitecube/nova-flexible-content/src/Layouts/Layout.php on line 504
[2022-07-18 12:55:37] local.INFO: null
[2022-07-18 12:55:37] local.INFO: "[{\"layout\":\"flex_content\",\"key\":\"M0t8gmxEkF1YwKbE\",\"attributes\":{\"M0t8gmxEkF1YwKbE__top_description\":\"

test<\/p>\",\"M0t8gmxEkF1YwKbE__bottom_description\":\"

test<\/p>\"}}]"
[2022-07-18 12:55:37] local.ERROR: Unable to parse incoming Flexible content, data should be an array. {"userId":1,"exception":"[object] (Exception(code: 0): Unable to parse incoming Flexible content, data should be an array. at /home/sark/www/test/vendor/whitecube/nova-flexible-content/src/Flexible.php:395)

toonvandenbos commented 2 years ago

Hmmm, besides the weird warning (which version of PHP are you using ?), it seems the field is receiving an unparsed JSON string. Meaning the HasOne field does not forward the parsed value. There is not much we can do about it right now, I'm afraid. Did you open an issue on Nova's repository ?

ZsarkZ commented 2 years ago

i use php 8.0 and i didn't open an issue on Nova's repository, thanks for help

ZsarkZ commented 2 years ago

Hmmm, besides the weird warning (which version of PHP are you using ?), it seems the field is receiving an unparsed JSON string. Meaning the HasOne field does not forward the parsed value. There is not much we can do about it right now, I'm afraid. Did you open an issue on Nova's repository ?

this is what they told me on nova repository

HasOne field has the correct structure and it is working as expected. It could just be the field isn't compatible with nova-flexible-content package.

toonvandenbos commented 2 years ago

In that case, maybe you should parse the field's value yourself using one of the available callbacks.

Kreshnik commented 7 months ago

I am encountering the same issue, has there by chance been any progress/update?

ZsarkZ commented 7 months ago

https://nova.laravel.com/docs/resources/repeater-fields.html