laravel 子查询用法

/**
 * 推荐的项目列表
 * @param $where
 * @param int $page
 * @param int $perpage
 * @return mixed
 */
public function get_invite_list($where, $page = 1, $perpage = 15)
{
    $subQuery = $this->orderBy('join_time','desc');
    $model = $this->from(DB::raw("({$subQuery->toSql()}) as inv"));
    if (isset($where['project_name']) && $where['project_name'] !== '') {
        $model->where('p.name', 'like', "%{$where['project_name']}%");
        unset($where['project_name']);
    }
    if ($where) {
        $model->where($where);
    }
    $model->select(DB::raw("p.id as id,p.name as project_name,p.status as status,inv.join_time as date_recorded,inv.point as point,sum(inv.point) as pointsum"));
    $model->groupBy('inv.use_id');
    $model->leftJoin('zb_project as p', 'p.id', '=', 'inv.use_id');
  //  echo $model->toSql();die;
    return $model->paginate($perpage);
}

你可能感兴趣的:(laravel 子查询用法)