Skip to content

Commit

Permalink
Merge pull request #393 from RezaAb/master
Browse files Browse the repository at this point in the history
Added some functions to Link's model and a bug fix
  • Loading branch information
AlirezaAlgo authored Jun 2, 2019
2 parents af63ed2 + 0e09489 commit 3569fe7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3569fe7

Please sign in to comment.