NavigationRepositoryEloquent.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Repositories;
  3. use Prettus\Repository\Eloquent\BaseRepository;
  4. use Prettus\Repository\Criteria\RequestCriteria;
  5. use App\Repositories\NavigationRepository;
  6. use App\Models\Navigation;
  7. /**
  8. * Class NavigationRepositoryEloquent
  9. * @package namespace App\Repositories;
  10. */
  11. class NavigationRepositoryEloquent extends BaseRepository implements NavigationRepository
  12. {
  13. /**
  14. * Specify Model class name
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return Navigation::class;
  21. }
  22. /**
  23. * Boot up the repository, pushing criteria
  24. */
  25. public function boot()
  26. {
  27. $this->pushCriteria(app(RequestCriteria::class));
  28. }
  29. /**
  30. * 设置分类为导航
  31. *
  32. * @param $categoryId
  33. * @param $categoryName
  34. * @return bool
  35. */
  36. public function setCategoryNav($categoryId, $categoryName)
  37. {
  38. $where = [
  39. ['article_cate_id', '=', $categoryId],
  40. ['nav_type', '=', 1]
  41. ];
  42. $navigation = $this->findWhere($where);
  43. if (!$navigation->isEmpty()) {
  44. return true;
  45. }
  46. $create['article_cate_id'] = $categoryId;
  47. $create['nav_type'] = 1;
  48. $create['name'] = $categoryName;
  49. $create['url'] = route('category', ['id' => $categoryId]);
  50. if ($this->create($create)) {
  51. return true;
  52. }
  53. return false;
  54. }
  55. }