File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed
Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change 77if (!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}
You can’t perform that action at this time.
0 commit comments