laravel 多表字段关联查询
public function items() { return $this->belongsToMany('App\Model\Cz\CzCourse', 'cz_picture_course', 'picture_id', 'course_id'); } //获取分类 public function getList() { $list=$this->with(['items'=>function($query){ $query->where('status',"1"); }])->where('status',1)->select('picture_id',"picture_type_name")->orderBy('sort', 'ASC')->get()->toArray(); foreach ($list as $k=>$item) { if (empty($item['items'])){ unset($list[$k]); } } return $list; }