laravel pagination get data code example

Example 1: paginate relationship laravel7

@foreach ($apps as $app)
    {{ $app->id }}
@endforeach

{!! $apps->render() !!}

Example 2: laravel pagination with get parameters

Suppose $users is a paginated eloquent collection

$users = User::paginate(10);

You can append attributes to the pagination links;

{{ $users->appends(['sort' => 'votes'])->links() }}

This would result in a url like /users?page=2&sort=votes

You can get the total record count with $users->total()

Example 3: access paginator object attribute in laravel

$paginator = $this->items()->where('position', '=', null)->paginate(15);
$paginator->getCollection()->transform(function ($value) {
    // Your code here
    return $value;
});

Tags:

Php Example