1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019-06-15
- * Time: 11:16
- */
- namespace App\Repositories;
- use App\Models\Category;
- use App\Models\CategoryTopic;
- class CategoryRepository {
- public function __construct(Category $category,CategoryTopic $categoryTopic) {
- $this->category = $category;
- $this->categoryTopic = $categoryTopic;
- }
- //列表
- public function lists($request)
- {
- $where = [];
- if(isset($request['is_suggest'])){
- $where[] = ['is_suggest', '=', $request['is_suggest']];
- }
- return $this->category->where($where)->get();
- }
- //获取多个话题
- public function getTopics($ids = []){
- return $this->categoryTopic
- ->leftJoin('topic', 'categoryTopic.topic_id', '=', 'topic.id')
- ->where('topic.is_suggest',1)
- ->whereIn('topic.category_id',$ids)
- ->select('topic.id','topic.name','topic.is_suggest')
- ->get();
- }
- }
|