outl1ne / nova-settings

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

Laravel Translatable support #6

Closed royduin closed 4 years ago

royduin commented 4 years ago

Added support for Laravel Translatable from Spatie: https://github.com/spatie/laravel-translatable, in my case I'm using this Nova integration: https://github.com/mrmonat/nova-translatable. An example to get this working:

\OptimistDigital\NovaSettings\NovaSettings::setSettingsFields([
    Translatable::make('Name'),
    Translatable::make('Description'),
], function ($key, $value) {
    return in_array($key, ['name', 'description']) ? json_decode($value) : $value;
});

Fixes: https://github.com/optimistdigital/nova-settings/issues/5

royduin commented 4 years ago

Please merge and tag a new version.

Tarpsvo commented 4 years ago

Hey! Sorry for the delay, I was busy and totally forgot. I merged it and released it in version 2.3.0.

A huge thank you for the contribution!

royduin commented 4 years ago

Great! Thanks 😎

Tarpsvo commented 4 years ago

Unfortunately, I had to undo the Translatable support in version 1.5.0 as it introduced too many breaking changes. Not being able to add an array as a setting's value without it getting encoded to a string doesn't seem like expected behaviour.

Isn't there any other way to provide support for Translatable?

royduin commented 4 years ago

I don't see the issue, do you have an example where this is breaking? When the value is an array you'll get an error about the array to string conversion...

Tarpsvo commented 4 years ago

You're right, I fucked up. Encoding is the correct way to go in this case, though I was using the value attribute for storing PHP arrays. I'll just refactor it and use json_decode for the value when required. Undid the release. 🤕

royduin commented 4 years ago

1.5.0 is still in Packagist @Tarpsvo.

Tarpsvo commented 4 years ago

Ah yeah, damn. Removed it now. Thanks!