Laravel provides pagination for Eloquent results out of the box, but for custom data, we need to do the pagination manually.
In this tutorial, I’ll use Laravel5 LengthAwarePaginator
class to show you how you can create a paginated list of results from an array of data.
Here is the Script –
Controller – app/Http/Controller/ItemsController.php
slice(($currentPage * $perPage) - $perPage, $perPage)->all(); // Create our paginator and pass it to the view $paginatedItems= new LengthAwarePaginator($currentPageItems , count($itemCollection), $perPage); // set url path for generted links $paginatedItems->setPath($request->url()); return view('items_view', ['items' => $paginatedItems]); } }
Here is the view file
resources/views/item_view.blade.php
Items List
-
@foreach ($items as $item)
- {{ $item }} @endforeach
{{ $items->links() }}
Define your route as shown below –
app/Http/Routes.php
Route::get('items','ItemsController@items');
hey can u help me
how array like this
$data[‘a’]=DB::select(“select * from table_name);
$data[‘b’]=DB::select(“select * from table_name);
return view(‘view.home’,$data);
how to add pagination like you do it
$data[‘a’] = DB::table(‘table_name’)->select(‘column’)->paginate(3);
return view(‘view’, [‘data’ => $data]);
in blade use {{ $data[‘a’]->links() }}
Thanks
thanks to tutorials, work it
Thank you for your guideline. It helps me to solve array data pagination issue.
Thanks man. You made my day easy
thank you. you are genius.
thank you so much
You are rock man!!
My project uses CURL to get all data through URL API. I am looking for a solution. Thanks man. Thanks to tutorials, work it. Thanks from Vietnam
Good work ! Thanks,
thanks,