From 2253743f885155d9016b5f914c64172706e13aa0 Mon Sep 17 00:00:00 2001 From: Reza Date: Sun, 2 Jun 2019 15:02:20 +0430 Subject: [PATCH 1/3] add some functions for managing Links --- src/models/Link.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/models/Link.php b/src/models/Link.php index 5265b4f..25cc31e 100644 --- a/src/models/Link.php +++ b/src/models/Link.php @@ -8,4 +8,33 @@ class Link extends Model { protected $fillable = ['url', 'display', 'show_menu']; protected $table = 'links'; + + static $cache = []; + public static function allCached($forceRefresh = false) + { + if (!isset(self::$cache['all']) || $forceRefresh) { + self::$cache['all'] = Link::all(); + } + return self::$cache['all']; + } + public static function returnUrls($forceRefresh = false) { + 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 getAndSave($url, $label, $visibility){ + $this->url = $url; + $this->display = $label; + $this->show_menu = $visibility; + $this->save(); + } } \ No newline at end of file From f8aaa78e1d04d59a81c8ba4d35130bcd57c7a66f Mon Sep 17 00:00:00 2001 From: Reza Date: Sun, 2 Jun 2019 15:04:27 +0430 Subject: [PATCH 2/3] fix function attributes in permission --- src/models/Permission.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 0e094894bdeb89021dd6f779252c47fb8a69ef14 Mon Sep 17 00:00:00 2001 From: Reza Date: Sun, 2 Jun 2019 15:24:41 +0430 Subject: [PATCH 3/3] change function name in Link class --- src/models/Link.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/models/Link.php b/src/models/Link.php index 25cc31e..07277a4 100644 --- a/src/models/Link.php +++ b/src/models/Link.php @@ -10,28 +10,31 @@ class Link extends Model { protected $table = 'links'; static $cache = []; - public static function allCached($forceRefresh = false) + 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 returnUrls($forceRefresh = false) { + 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){ + 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 getAndSave($url, $label, $visibility){ + public function addNewLink($url, $label, $visibility) // getAndSave( + { $this->url = $url; $this->display = $label; $this->show_menu = $visibility;