Manual pagination with Laravel 5.*

manual paginate with laravel



use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
... 

$array = [12,23,34,45];
$page = Input::get('page', 1); // Get the current page or default to 1, this is what you miss!
$perPage = 20;
$offset = ($page * $perPage) - $perPage;

return new LengthAwarePaginator(array_slice($array, $offset, $perPage, true), count($array), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()]);

 

source: https://laracasts.com/discuss/channels/laravel/laravel-pagination-not-working-with-array-instead-of-collection

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s