Skip to content

Instantly share code, notes, and snippets.

@waqasraza123
Created May 8, 2017 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waqasraza123/ca84d3d5779cde6629e47612e8d49754 to your computer and use it in GitHub Desktop.
Save waqasraza123/ca84d3d5779cde6629e47612e8d49754 to your computer and use it in GitHub Desktop.
<?php
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
//Create a new Laravel collection from the array data
$collection = new Collection($data);
//Define how many items we want to be visible in each page
$perPage = 48;
//Slice the collection to get the items to display in current page
$currentPageSearchResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all();
//Create our paginator and pass it to the view
$paginatedSearchResults = new LengthAwarePaginator($data, $count, $perPage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment