Introduction
Pagination helps split large lists of data into smaller pages. This makes it easier to read and faster to load.
Pagination helps split large lists of data into smaller pages. This makes it easier to read and faster to load.
$items = Model::paginate(10);
// In Blade view
{{ $items->links() }}paginate(number) to get a set number of items per page.links() in your Blade template to show page links.$users = User::paginate(5); return view('users.index', compact('users'));
<!-- In Blade template -->
@foreach ($users as $user)
<p>{{ $user->name }}</p>
@endforeach
{{ $users->links() }}$posts = Post::where('status', 'published')->paginate(15);
This controller gets 3 products per page. The Blade view shows product names and prices, then page links.
<?php namespace App\Http\Controllers; use App\Models\Product; use Illuminate\Http\Request; class ProductController extends Controller { public function index() { $products = Product::paginate(3); return view('products.index', compact('products')); } } // Blade file: resources/views/products/index.blade.php /* @foreach ($products as $product) <div>{{ $product->name }} - ${{ $product->price }}</div> @endforeach {{ $products->links() }} */
Pagination automatically reads the current page from the URL query (like ?page=2).
You can customize the pagination view if you want different styles.
Use simplePaginate() for simpler next/previous links without page numbers.
Pagination splits data into pages to improve usability and speed.
Use paginate() in your query and links() in your Blade view.
Laravel handles page numbers and URLs automatically.
paginate() in Laravel?paginate() method divides a large set of data into smaller chunks or pages.paginate() method accepts the number of items per page as an argument, like paginate(10).get(10) does not paginate, limit(10)->paginate() is incorrect usage, and paginate()->take(10) is invalid chaining.$posts = Post::paginate(5);
@foreach ($posts as $post)
{{ $post->title }}
@endforeach
{{ $posts->links() }}paginate(5) limits results to 5 per page. links() generates page navigation links automatically.$users = User::paginate;
paginate is a method and must be called with parentheses ().User::paginate to User::paginate() to fix the error.paginate(15) to show 15 items per page.'pagination::bootstrap-5' to links() to apply Bootstrap 5 styles.paginate(15, 'bootstrap-5') incorrectly passes the style to paginate(), links('bootstrap') uses wrong view name, and plain links() uses default style.Pass the test and this pattern moves unknown