https://gist.github.com/vluzrmos/3ce756322702331fdf2bf414fea27bcb
<?php
// In our top of class
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
// In our index method, $data is a single array of values or a collection array
$entries = $this->paginate($data) ;
dd( $entries ) ;
// Method inside our class
public function paginate($items, $perPage = 10, $page = null, $options = [])
{
// path array is $options
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, ['path' => LengthAwarePaginator::resolveCurrentPath()]);
}