laravel 联合查询

$data = $this->where($filter)
            ->select('xiu_score_log.*','xiu_user_customer.name','xiu_user_customer.phone')
            ->leftJoin('xiu_user_customer', 'xiu_score_log.u_id', '=', 'xiu_user_customer.id')
//            ->with(['posts'])
            ->offset($start)
            ->limit($length)
            ->get();

关于with里面的posts这是写在ScoreModel里

  public function posts()
    {
        return $this->belongsTo('App\Http\Model\UserCustomerModel','u_id');
    }

使用with就类似于tp框架里 foreach循环向列表里插入子列

猜你喜欢

转载自blog.csdn.net/helloworld_dream/article/details/83152448
今日推荐