pagination in laravel code example

Example 1: paginate relationship laravel7

$category = Category::first();
$apps = $category->apps()->paginate(10);
return view('example', compact('category', 'apps'));

Example 2: paginate relationship laravel7

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

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

Example 3: laravel pagination

{{ $users->withQueryString()->links() }}

Example 4: laravel pagination

DB::table('users') -> paginate(15)

Example 5: 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 6: laravel pagination

// in, AppServiceProvider -> boot() - set: 
Paginator::useBootstrap();  // for compatibility with bootstrap

// in controller 
$storage = Model::paginate(10);

// in view 
{!! $storage->links() !!}

Tags:

Php Example