Laravel 5 manual pagination with array example

By Hardik Savani | March 21, 2016 | Category : Laravel

If you neeed to create custom pagination of your array, you can learn from this post. basically we are doing pagination with model or DB facade like "User::paginate(10)" OR "DB::table('users')->paginate(10)". But now if you have new array and you want to make pagination on your array then you can also give using "LengthAwarePaginator" class see following example:


public function myData($userid)


$data = static::get();

$result = [];


foreach ($data as $key => $value) {

$result[$value->type.'-'.$value->postid][] = $value;



$paginate = 10;

$page = Input::get('page', 1);

$offSet = ($page * $paginate) - $paginate;

$itemsForCurrentPage = array_slice($result, $offSet, $paginate, true);

$result = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, count($result), $paginate, $page);

$result = $result->toArray();

return $result;


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: