Skip to content

Commit

Permalink
when setting file not exists, not crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Mar 7, 2022
1 parent d753a0b commit 8c6d672
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/helpers.php
Expand Up @@ -6,7 +6,12 @@ function setting($key, $default = '', $setting_name = 'site')
{
if ( ! config()->get($setting_name)) {
// Decode the settings to an associative array.
$site_settings = json_decode(file_get_contents(storage_path("/administrator_settings/$setting_name.json")), true);
$file_path = storage_path("/administrator_settings/$setting_name.json");
if (file_exists($file_path)) {
$site_settings = json_decode(file_get_contents($file_path), true);
} else {
$site_settings = [];
}
// Add the site settings to the application configuration
config()->set($setting_name, $site_settings);
}
Expand All @@ -21,7 +26,12 @@ function admin_setting($key, $default = '', $setting_name = 'site')
{
if ( ! config()->get($setting_name)) {
// Decode the settings to an associative array.
$site_settings = json_decode(file_get_contents(storage_path("/administrator_settings/$setting_name.json")), true);
$file_path = storage_path("/administrator_settings/$setting_name.json");
if (file_exists($file_path)) {
$site_settings = json_decode(file_get_contents($file_path), true);
} else {
$site_settings = [];
}
// Add the site settings to the application configuration
config()->set($setting_name, $site_settings);
}
Expand Down

0 comments on commit 8c6d672

Please sign in to comment.