NavigationRepository.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Navigation;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. use Illuminate\Support\Facades\Cache;
  6. /**
  7. * Class ArticleRepositoryEloquent.
  8. *
  9. * @package namespace App\Repositories;
  10. */
  11. class NavigationRepository extends BaseRepository
  12. {
  13. public function model()
  14. {
  15. return Navigation::class;
  16. }
  17. public function getNav($where)
  18. {
  19. return $this->model->where($where)->first();
  20. }
  21. public function getTopNavs($where)
  22. {
  23. return $this->model->where($where)->orderBy('order', 'asc')->get();
  24. }
  25. public function getNavs()
  26. {
  27. //Cache::forget('nav_list');
  28. //Cache::flush();
  29. if (null === $nav_list = Cache::get('nav_list')) {
  30. $navs = $this->model->select('alias', 'title', 'urltype', 'pagealias', 'tag', 'target', 'color', 'order', 'url', 'is_personal')
  31. ->where(array('display'=>'1'))
  32. ->orderBy('order', 'asc')
  33. ->get();
  34. $nav_list = array();
  35. foreach ($navs as $val) {
  36. $k = $val->alias;
  37. if ($val->color) {
  38. $val->title = "<font color='".$val->color."'>".$val->title."</font>";
  39. }
  40. $nav_list[$k][] = $val;
  41. }
  42. Cache::forever('nav_list', $nav_list);
  43. }
  44. return $nav_list;
  45. }
  46. }