Skip to content

Commit 3569fe7

Browse files
authored
Merge pull request #393 from RezaAb/master
Added some functions to Link's model and a bug fix
2 parents af63ed2 + 0e09489 commit 3569fe7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/models/Link.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/models/Permission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)