@IamCrazyD you can do something like that into a controller or anywhere you want to use it...
use Illuminate\Pagination\LengthAwarePaginator;
/**
* Create a length aware custom paginator instance.
*
* @param Collection $items
* @param int $perPage
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
protected function paginate($items, $perPage = 12)
{
//Get current page form url e.g. &page=1
$currentPage = LengthAwarePaginator::resolveCurrentPage();
//Slice the collection to get the items to display in current page
$currentPageItems = $items->slice(($currentPage - 1) * $perPage, $perPage);
//Create our paginator and pass it to the view
return new LengthAwarePaginator($currentPageItems, count($items), $perPage);
}
public function index()
{
$articles = $this
->paginate($this->foo->getArticles())
->setPath('articles');
}
It's just to give you the idea.