File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,36 @@ class Link extends Model {
88 protected $ fillable = ['url ' , 'display ' , 'show_menu ' ];
99
1010 protected $ table = 'links ' ;
11+
12+ static $ cache = [];
13+ public static function getAllLinks ($ forceRefresh = false ) // allCached(
14+ {
15+ if (!isset (self ::$ cache ['all ' ]) || $ forceRefresh ) {
16+ self ::$ cache ['all ' ] = Link::all ();
17+ }
18+ return self ::$ cache ['all ' ];
19+ }
20+ public static function getUrls ($ forceRefresh = false ) // returnUrls(
21+ {
22+ if (!isset (self ::$ cache ['all_urls ' ]) || $ forceRefresh ) {
23+ $ configs = Link::allCached ($ forceRefresh );
24+ self ::$ cache ['all_urls ' ] = $ configs ->pluck ('url ' )->toArray ();
25+ }
26+ return self ::$ cache ['all_urls ' ];
27+ }
28+ public static function getMainUrls ($ forceRefresh = false )
29+ {
30+ if (!isset (self ::$ cache ['main_urls ' ]) || $ forceRefresh ) {
31+ $ configs = Link::where ('main ' , '= ' , true )->get (['url ' ]);
32+ self ::$ cache ['main_urls ' ] = $ configs ->pluck ('url ' )->toArray ();
33+ }
34+ return self ::$ cache ['main_urls ' ];
35+ }
36+ public function addNewLink ($ url , $ label , $ visibility ) // getAndSave(
37+ {
38+ $ this ->url = $ url ;
39+ $ this ->display = $ label ;
40+ $ this ->show_menu = $ visibility ;
41+ $ this ->save ();
42+ }
1143}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public function roles()
1919 return $ this ->belongsToMany (Role::class);
2020 }
2121
22- public function getAndSave ($ url , $ label ){
22+ public function getAndSave ($ name , $ label ){
2323 $ this ->name = $ name ;
2424 $ this ->label = $ label ;
2525 $ this ->save ();
You can’t perform that action at this time.
0 commit comments