search

Home  >  Q&A  >  body text

There is an error in having contiguous paging function paginate during laravel data operation. What's going on?

The database data is like this:

I want to use the having statement to get out counts > 0;
uses paging, so having is followed by the paging function paginate

But this error is reported:

If I having is followed by the get() function, then there is no problem,

You can find the data of counts > 0

What's going on?

Is having followed by the paging function paginate a bug?
How to solve it?

某草草某草草2782 days ago934

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 16:51:05

    paginate source code

    public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
        {
            $page = $page ?: Paginator::resolveCurrentPage($pageName);
            $total = $this->getCountForPagination($columns);
            $results = $total ? $this->forPage($page, $perPage)->get($columns) : collect();
            return new LengthAwarePaginator($results, $total, $perPage, $page, [
                'path' => Paginator::resolveCurrentPath(),
                'pageName' => $pageName,
            ]);
        }

    paginate takes the fields in the table by default, and there are no fields in the tablecounts
    可换成skip($offset)->take($limit)

    reply
    0
  • Cancelreply