outl1ne / nova-settings

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

Allow assigning default values with requesting multiple settings #96

Closed KasparRosin closed 2 years ago

KasparRosin commented 2 years ago

Implements feature that allows passing an array of default values to nova_get_settings.

Additionally, the helper will now return null values for keys that don't have default value and that are not stored in database. Previously the key would not have been returned, which could have caused undefined index exceptions if not handled.

Currently

$settings = nova_get_settings(['non_existant_key']);
$settings === [];

After

$settings = nova_get_settings(['non_existant_key']);
$settings === ['non_existant_key' => null];

// With default values
$settings = nova_get_settings(['non_existant_key'], ['non_existant_key' => 'default']);
$settings === ['non_existant_key' => 'default'];