whitecube / nova-flexible-content

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

Fail to update resource if one of the field name has the same name as one of the nested flexible fields #111

Open milewski opened 4 years ago

milewski commented 4 years ago

Hello, currently the following fails if I have a nested flexible field with the same name as one of standard fields:

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Textarea::make(__('Content'), 'content')->rows(4)->rules('required'),

        Flexible::make(__('Panels'), 'panels')
                ->addLayout(__('Panel'), 'panel', [
                    Text::make(__('Title'), 'title')->rules('required'),

                    Filepond::make(__('Icon'), 'icon')
                            ->image()                           
                            ->rules('required'),

                    Flexible::make(__('Content'), 'content')
                            ->preset(ContentPreset::class)
                            ->button(__('Add Panel'))
                ]),

    ];
}

image

image

{
    "message": "Unable to parse incoming Flexible content, data should be an array.",
    "exception": "Exception",
    "file": "/data/vendor/whitecube/nova-flexible-content/src/Flexible.php",
    "line": 309,
    "trace": [
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Flexible.php",
            "line": 422,
            "function": "extractValue",
            "class": "Whitecube\\NovaFlexibleContent\\Flexible",
            "type": "->"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Flexible.php",
            "line": 409,
            "function": "getFlexibleRules",
            "class": "Whitecube\\NovaFlexibleContent\\Flexible",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Fields/Field.php",
            "line": 680,
            "function": "getUpdateRules",
            "class": "Whitecube\\NovaFlexibleContent\\Flexible",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/helpers.php",
            "line": 546,
            "function": "Laravel\\Nova\\Fields\\{closure}",
            "class": "Laravel\\Nova\\Fields\\Field",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Fields/Field.php",
            "line": 684,
            "function": "with"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Fields/Field.php",
            "line": 705,
            "function": "isRequired",
            "class": "Laravel\\Nova\\Fields\\Field",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/Traits/EnumeratesValues.php",
            "line": 709,
            "function": "jsonSerialize",
            "class": "Laravel\\Nova\\Fields\\Field",
            "type": "->"
        },
        {
            "function": "Illuminate\\Support\\Traits\\{closure}",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/Traits/EnumeratesValues.php",
            "line": 717,
            "function": "array_map"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Layouts/Layout.php",
            "line": 225,
            "function": "jsonSerialize",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Layouts/Layout.php",
            "line": 157,
            "function": "getResolvedValue",
            "class": "Whitecube\\NovaFlexibleContent\\Layouts\\Layout",
            "type": "->"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Flexible.php",
            "line": 324,
            "function": "getResolved",
            "class": "Whitecube\\NovaFlexibleContent\\Layouts\\Layout",
            "type": "->"
        },
        {
            "function": "Whitecube\\NovaFlexibleContent\\{closure}",
            "class": "Whitecube\\NovaFlexibleContent\\Flexible",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/Collection.php",
            "line": 638,
            "function": "array_map"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Flexible.php",
            "line": 325,
            "function": "map",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Flexible.php",
            "line": 226,
            "function": "resolveGroups",
            "class": "Whitecube\\NovaFlexibleContent\\Flexible",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/HigherOrderCollectionProxy.php",
            "line": 60,
            "function": "resolve",
            "class": "Whitecube\\NovaFlexibleContent\\Flexible",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/Traits/EnumeratesValues.php",
            "line": 176,
            "function": "Illuminate\\Support\\{closure}",
            "class": "Illuminate\\Support\\HigherOrderCollectionProxy",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/HigherOrderCollectionProxy.php",
            "line": 61,
            "function": "each",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/ResolvesFields.php",
            "line": 250,
            "function": "__call",
            "class": "Illuminate\\Support\\HigherOrderCollectionProxy",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/ResolvesFields.php",
            "line": 172,
            "function": "resolveFields",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/ResolvesFields.php",
            "line": 183,
            "function": "updateFields",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/FillsFields.php",
            "line": 35,
            "function": "updateFieldsWithoutReadonly",
            "class": "Laravel\\Nova\\Resource",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Controllers/ResourceUpdateController.php",
            "line": 32,
            "function": "fillForUpdate",
            "class": "Laravel\\Nova\\Resource",
            "type": "::"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php",
            "line": 29,
            "function": "Laravel\\Nova\\Http\\Controllers\\{closure}",
            "class": "Laravel\\Nova\\Http\\Controllers\\ResourceUpdateController",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php",
            "line": 349,
            "function": "transaction",
            "class": "Illuminate\\Database\\Connection",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php",
            "line": 239,
            "function": "__call",
            "class": "Illuminate\\Database\\DatabaseManager",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Controllers/ResourceUpdateController.php",
            "line": 41,
            "function": "__callStatic",
            "class": "Illuminate\\Support\\Facades\\Facade",
            "type": "::"
        },
        {
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Controllers\\ResourceUpdateController",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 219,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 176,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 680,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/data/vendor/whitecube/nova-flexible-content/src/Http/Middleware/InterceptFlexibleAttributes.php",
            "line": 33,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Whitecube\\NovaFlexibleContent\\Http\\Middleware\\InterceptFlexibleAttributes",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Middleware/Authorize.php",
            "line": 18,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\Authorize",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Middleware/BootTools.php",
            "line": 20,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\BootTools",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Middleware/DispatchServingNovaEvent.php",
            "line": 20,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\DispatchServingNovaEvent",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
            "line": 43,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Middleware/Authenticate.php",
            "line": 31,
            "function": "handle",
            "class": "Illuminate\\Auth\\Middleware\\Authenticate",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\Authenticate",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php",
            "line": 76,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php",
            "line": 49,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\View\\Middleware\\ShareErrorsFromSession",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
            "line": 56,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Session\\Middleware\\StartSession",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php",
            "line": 37,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php",
            "line": 66,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\EncryptCookies",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 682,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 657,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 623,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 612,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 176,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/nova/src/Http/Middleware/ServeNova.php",
            "line": 26,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Laravel\\Nova\\Http\\Middleware\\ServeNova",
            "type": "->"
        },
        {
            "file": "/data/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php",
            "line": 58,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 62,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/data/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 151,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/data/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 116,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/data/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}
voidgraphics commented 4 years ago

Thanks for the detailed report! The bug might come from somewhere in the ParsesFlexibleAttributes trait that is used on the InterceptFlexibleAttributes middleware to apply validation rules to flexible fields. I do not have time to properly track it down now, but it seems like a good place to start looking.