K
K
kostya17042020-12-30 22:02:03
Laravel
kostya1704, 2020-12-30 22:02:03

How to make pagination for request with parameters in laravel?

There is a request:

$poisks = DB::table('items')
 ->where('brand',$brand)
 ->where('location',$location)
 ->whereIn('fuel_type',[$fuel_type])
 ->whereBetween('price', [$price_from, $price_to])
 ->whereIn('body_type', [$body_type])
 ->whereIn('fuel_type', [$fuel_type])
 ->whereIn('model', [$model])
 ->paginate(10);

The request returns the result of the first page, there is a pagination block, when you go to the next well or any other pagination page, it gives - "Undefined index: brand" and so on. But in the $_POST.
Laravel manual - "Currently, paging operations that use the groupBy operator cannot be performed efficiently in Laravel. If you need to use groupBy for a paginated result set, it is recommended to query the database and instantiate the paging manually.
This can be done by creating either an Illuminate\Pagination\Paginator instance or an Illuminate\Pagination\LengthAwarePaginator instance, depending on the
situation
.
Does that mean there is no built-in pagination in Laravel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sklyarov, 2020-12-30
@0example

If I understand you, you can simply call the method appends($request->query())on the collection.
For example, in your case:

$poisks = DB::table('items')
 ->where('brand',$brand)
 ->where('location',$location)
 ->whereIn('fuel_type',[$fuel_type])
 ->whereBetween('price', [$price_from, $price_to])
 ->whereIn('body_type', [$body_type])
 ->whereIn('fuel_type', [$fuel_type])
 ->whereIn('model', [$model])
 ->paginate(10)
->appends($request->query());

Output the pagination itself in the blade template like this:
{{ $poisks->links() }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question