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;
    }

 

posted @ 2019-04-16 11:54  phpwyl  阅读(3730)  评论(0编辑  收藏  举报