← BACK
Laravel / Eloquent

Control Pagination Link Density with onEachSide()

Punyapal Shah • • 1 min read
edit this tip →

Use onEachSide() on paginated Eloquent queries to adjust the number of page links shown beside the current page.

Default pagination controls can show too many numeric page links on mobile viewports. Calling onEachSide(1) limits pagination controls to a clean, minimal set of links.

use App\Models\User;

// Displays 1 page link on each side of the active page
$users = User::paginate(15)->onEachSide(1);
  • Controls how many numeric page buttons display beside active page number
  • Prevents pagination controls from overflowing narrow mobile viewports
  • Works out of the box with default Blade pagination templates

Related Tips

View all tips →

// Got a tip in mind? Contributions are always welcome