Laravel 5 manual pagination with array example

Laravel 5 manual pagination with array example

In this post we will give you information about Laravel 5 manual pagination with array example. Hear we will give you detail about Laravel 5 manual pagination with array exampleAnd how to use it also give you demo for it if it is necessary.

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:

Example:

Also see:Laravel 5 – elasticsearch with pagination example

public function myData($userid)

{

$data = static::get();


$result = [];

if(!empty($data)){

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 IlluminatePaginationLengthAwarePaginator($itemsForCurrentPage, count($result), $paginate, $page);

$result = $result->toArray();

return $result;

}

Hope this code and post will helped you for implement Laravel 5 manual pagination with array example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

6  +  4  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US