stepanenko3 / nova-settings

This Laravel Nova settings tool based on env, using nativ nova fields and resources
MIT License
31 stars 5 forks source link

Supporting the repeater field #13

Open graphem opened 9 months ago

graphem commented 9 months ago

Hi! Great package, love it so far.

I am trying to make the Nova repeater field work, it seems to work at first and the data is saved, however, it is not parse back right when trying to edit, so it shows up as empty in the nova UI, but still in the DB.

Could be an issue with preparing the data back since it is a json field inside the json field.

Also I have a similar issue with the multiselect, the value are not preserved when editing back.

Thanks a lot!

stepanenko3 commented 5 months ago

Hi, @graphem Pls send me code example

makowskid commented 4 months ago

If you have your model that inherits from \Stepanenko3\NovaSettings\Models\Settings

then you have to add array casting to a model that you use as a resource in NOVA:

    protected $casts = [
        'fields' => 'array',
        'settings' => 'array',
    ];

so you will get

class Settings extends \Stepanenko3\NovaSettings\Models\Settings
{
    use HasFactory;
    use LogsActivity;

    protected $casts = [
        'fields' => 'array',
        'settings' => 'array',
    ];

}