How can I get and paginate the last 1000 records with relationship?
i try this but this return all data
$logbooks = $this->log_book->orderBy('created_at','desc')->skip(10000)->take(1000)->paginate(100);
How can I get and paginate the last 1000 records with relationship?
i try this but this return all data
$logbooks = $this->log_book->orderBy('created_at','desc')->skip(10000)->take(1000)->paginate(100);
Only what can i do is use this macro for pagination on collection, so add this code to my AppServiceProvider
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') {
$page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
return new LengthAwarePaginator($this->forPage($page, $perPage), $total ?: $this->count(), $perPage, $page, [
'path' => LengthAwarePaginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
});
Then i will paginate on the collection
$logbooks = $this->log_book->orderBy('created_at','desc')->limit(1000)->get();
$logbooks->paginate(100);