CategoryRepository.php 1001 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019-06-15
  6. * Time: 11:16
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Category;
  10. use App\Models\CategoryTopic;
  11. class CategoryRepository {
  12. public function __construct(Category $category,CategoryTopic $categoryTopic) {
  13. $this->category = $category;
  14. $this->categoryTopic = $categoryTopic;
  15. }
  16. //列表
  17. public function lists($request)
  18. {
  19. $where = [];
  20. if(isset($request['is_suggest'])){
  21. $where[] = ['is_suggest', '=', $request['is_suggest']];
  22. }
  23. return $this->category->where($where)->get();
  24. }
  25. //获取多个话题
  26. public function getTopics($ids = []){
  27. return $this->categoryTopic
  28. ->leftJoin('topic', 'categoryTopic.topic_id', '=', 'topic.id')
  29. ->where('topic.is_suggest',1)
  30. ->whereIn('topic.category_id',$ids)
  31. ->select('topic.id','topic.name','topic.is_suggest')
  32. ->get();
  33. }
  34. }