Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom type casting #43

Open
manojhl opened this issue Dec 9, 2020 · 2 comments
Open

Using custom type casting #43

manojhl opened this issue Dec 9, 2020 · 2 comments

Comments

@manojhl
Copy link

manojhl commented Dec 9, 2020

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
Copy link

eboye commented Jun 9, 2021

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

@thisprojectworks
Copy link

thisprojectworks commented Apr 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants