outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
273 stars 97 forks source link

Using custom type casting #43

Open manojhl opened 3 years ago

manojhl commented 3 years ago

I was trying to use Nova Flexible Content with nova settings.

Nova Flexible Content has a custom cast type which needs to be used in order for it to work properly. I believe this is not supported at this time.

The problem lies with saving the data. Every time the settings are saved any image filed within the flexible model will be set to null unless an image is selected every time.

    \OptimistDigital\NovaSettings\NovaSettings::addSettingsFields([
            Boolean::make('Use these slides on Homepage', 'use-on-homepage'),

            Flexible::make('Slides', 'slides')
                ->addLayout('Image slide', 'image', [
                    Color::make('Background Color', 'bg-color')->compact(),
                    Image::make('Desktop Image', 'desktopimage')->rules('')->disk('public'),
                    // Avatar::make('Desktop Image', 'desktop-image')->rules('')->disk('public'),
                    Image::make('Tablet Image (optional)', 'tablet-image')->disk('public')
                        ->help('If left empty desktop image will be used as fallback.'),
                    Image::make('Mobile Image', 'mobile-image'),
                    Text::make('Alternative text', 'alttext')->rules('required'),
                ])
                ->button('Add slide'),
        ], [
            'use-on-homepage' => 'boolean',
            'slides' => FlexibleCast::class
            // 'slides' => 'array',
            // 'slides' => 'collection',
        ], 'Homepage');

I tried creating a custom Setting Model but this didn't work as it doesn't follow the Laravel standard casting.

I tried to implement a custom cast case inside getValueAttribute method, but again it didn't work. image

I was hoping you could help me with finding a solution to my problem. I would appreciate any suggestions or direction.

Thanks

eboye commented 3 years ago

I have this issue also ... I tried a lot from what you described, but to no success :(

thisprojectworks commented 3 months ago

Same problem here. The problem is occurring when I use an Image Field inside A Flexible Field inside the Nova Settings package. If I use in a model, works well. If I save for first time everything works correctly and the images are saved on the disk and in the json field. But If I let empty the Image field with a previous image saved, the field image is removed from the json of the Flexible content, both key and value.

Laravel 11 whitecube/nova-flexible-conten 1.1 outl1ne/nova-settings 5.2