outl1ne / nova-settings

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

Nullable settings with value NULL are not persisted #169

Closed Senexis closed 11 months ago

Senexis commented 11 months ago

Commit f775ca2220ea93e34a7932fbc537b4de55c25539 introduced a bug where if you have a nullable setting and you leave it empty (thus turning into NULL) the setting is not persisted. This is due to the following line:

if (!isset($tempResource->{$field->attribute})) return;

It used to be property_exists, but has been changed to isset. Since isset also detected NULL, this skips saving the value when it is NULL.

Suggested fix

if (!array_key_exists($field->attribute, $tempResource->getAttributes())) return;

This checks if the $tempResource has the attribute as an array key in its attributes. It doesn't check whether it's null, just that it's set. This should prevent any cases where undefined attributes get persisted, though is that even possible?

exshapoval commented 11 months ago

I really need it too, please fix it

Tarpsvo commented 11 months ago

Heya! Sorry about the delay. FIxed now in version 5.2.1.