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

 

转载于:https://www.cnblogs.com/phpwyl/p/10716090.html

你可能感兴趣的:(laravel 多表字段关联查询)