美文网首页
laravel 子查询用法

laravel 子查询用法

作者: gurlan | 来源:发表于2019-05-14 15:06 被阅读0次
    /**
     * 推荐的项目列表
     * @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 子查询用法

          本文链接:https://www.haomeiwen.com/subject/ebisaqtx.html