| 1 | <?php |
||
| 6 | class Link extends Model { |
||
| 7 | |||
| 8 | protected $table = 'links'; |
||
| 9 | |||
| 10 | static $cache = []; |
||
| 11 | |||
| 12 | public static function allCached($forceRefresh = false) |
||
| 13 | { |
||
| 14 | if (!isset(self::$cache['all']) || $forceRefresh) { |
||
| 15 | self::$cache['all'] = Link::all(); |
||
| 16 | } |
||
| 17 | |||
| 18 | return self::$cache['all']; |
||
| 19 | } |
||
| 20 | |||
| 21 | public static function returnUrls($forceRefresh = false) { |
||
| 22 | |||
| 23 | if (!isset(self::$cache['all_urls']) || $forceRefresh) { |
||
| 24 | $configs = Link::allCached($forceRefresh); |
||
| 25 | self::$cache['all_urls'] = $configs->pluck('url')->toArray(); |
||
| 26 | } |
||
| 27 | |||
| 28 | return self::$cache['all_urls']; |
||
| 29 | } |
||
| 30 | |||
| 31 | public static function getMainUrls($forceRefresh = false){ |
||
| 32 | |||
| 33 | if (!isset(self::$cache['main_urls']) || $forceRefresh) { |
||
| 34 | $configs = Link::where('main', '=', true)->get(['url']); |
||
| 35 | self::$cache['main_urls'] = $configs->pluck('url')->toArray(); |
||
| 36 | } |
||
| 37 | |||
| 38 | return self::$cache['main_urls']; |
||
| 39 | } |
||
| 40 | |||
| 41 | |||
| 42 | public function getAndSave($url, $display){ |
||
| 47 | |||
| 48 | |||
| 49 | protected $fillable = array('url', 'display'); |
||
| 50 | |||
| 51 | } |
||
| 52 |