diff --git a/src/models/Link.php b/src/models/Link.php index 5265b4f..07277a4 100644 --- a/src/models/Link.php +++ b/src/models/Link.php @@ -8,4 +8,36 @@ class Link extends Model { protected $fillable = ['url', 'display', 'show_menu']; protected $table = 'links'; + + static $cache = []; + public static function getAllLinks($forceRefresh = false) // allCached( + { + if (!isset(self::$cache['all']) || $forceRefresh) { + self::$cache['all'] = Link::all(); + } + return self::$cache['all']; + } + public static function getUrls($forceRefresh = false) // returnUrls( + { + if (!isset(self::$cache['all_urls']) || $forceRefresh) { + $configs = Link::allCached($forceRefresh); + self::$cache['all_urls'] = $configs->pluck('url')->toArray(); + } + return self::$cache['all_urls']; + } + public static function getMainUrls($forceRefresh = false) + { + if (!isset(self::$cache['main_urls']) || $forceRefresh) { + $configs = Link::where('main', '=', true)->get(['url']); + self::$cache['main_urls'] = $configs->pluck('url')->toArray(); + } + return self::$cache['main_urls']; + } + public function addNewLink($url, $label, $visibility) // getAndSave( + { + $this->url = $url; + $this->display = $label; + $this->show_menu = $visibility; + $this->save(); + } } \ No newline at end of file diff --git a/src/models/Permission.php b/src/models/Permission.php index 60ffd08..979b16a 100644 --- a/src/models/Permission.php +++ b/src/models/Permission.php @@ -19,7 +19,7 @@ public function roles() return $this->belongsToMany(Role::class); } - public function getAndSave($url, $label){ + public function getAndSave($name, $label){ $this->name = $name; $this->label = $label; $this->save();