Skip to content

Commit 940bab3

Browse files
Update helpers.php
1 parent 96a82ef commit 940bab3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

app/helpers.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@
77
if (!function_exists('setting')) {
88
function setting(String|array $name, $default = null)
99
{
10-
$changed = false; // $user->isDirty(); // true
11-
$key = "settings." . Str::slug($name, '.');
12-
if (Cache::has($key) and !$changed) {
13-
return Cache::get($key);
14-
}
10+
if (is_string($name)) {
11+
$changed = false; // $user->isDirty(); // true
12+
$prefix = "settings." . Str::slug($name, '.');
13+
if (Cache::has($prefix) and !$changed) {
14+
return Cache::get($prefix);
15+
}
1516

16-
$setting = Setting::where('name', $name)->Orwhere('config', $name)->value('value');
17+
$setting = Setting::where('name', $name)->Orwhere('config', $name)->value('value') ?? $default;
1718

18-
if ($setting) {
19-
$value = $setting;
19+
Cache::put($prefix, $setting, 60);
20+
return $setting;
2021
} else {
21-
$value = $default;
22-
}
22+
foreach ($name as $key => $value) {
23+
$setting = Setting::firstOrCreate(['name' => $key, 'value' => $value])->value('value');
2324

24-
Cache::put($key, $value, 60);
25-
return $value;
25+
$prefix = "settings." . Str::slug($key, '.');
26+
Cache::put($prefix, $setting, 60);
27+
}
28+
}
2629
}
2730
}

0 commit comments

Comments
 (0)