$keyword = $this->filters['keyword'];
$options = $this->parseOptions();
$datas = TableModel::with('hasBook')
->with('hasGradeCell.hasGrade')
->when($keyword,function($query)use($keyword){
return $query->where('title','like','%'.$keyword.'%');
})
->when($options,function ($query) use ($options){
if (isset($options['cell_id'])) {
return $query->where('cell_id', $options['cell_id']);
}
if (isset($options['grade_id'])) {
return $query->whereHas('hasGradeCell',function ($query) use ($options){
return $query->whereHas('hasGrade',function ($query) use ($options){
return $query->where('id',$options['grade_id']);
});
});
}
});
$counts = $datas->count();
$datas = $datas->where('type', 1)
->orderBy($this->filters['sort'], $this->filters['sort_by'])
->paginate($this->filters['limit'])
->appends($this->filters);
牛哇