Custom pagination view in Laravel 5

Custom pagination view in Laravel 5

  1. Blog
  2. 15 November 2026
  3. 6 min read

Stefan Bogdanescu

Founder & Senior Architect

Bypassing the Hardcoded Pagination in Laravel 5

Laravel 4.2 offered a straightforward mechanism to override the default pagination view by editing the pagination key in app/config/view.php. You could simply point this configuration to a custom Blade file, and every page of results would render using your specific layout. This capability vanished in Laravel 5. The configuration array was restructured, and the specific setting for pagination views was removed from config/view.php.

This shift might seem like an inconvenience if you rely on a specific design system or need to inject custom logic directly into the pagination wrapper. However, replicating this behavior is entirely possible without modifying the global configuration file. The solution involves understanding how Laravel resolves views and leveraging the framework's service container.

Understanding the View Resolution Chain

In Laravel 5, when Paginator->links() is called, it attempts to render the view specified by the pagination.view configuration key. Since this key no longer exists in config/view.php, the framework defaults to looking for a view named pagination::simple-bootstrap-4 (or similar, depending on your version), which resides inside the resources/views/vendor/pagination directory.

To override this, you do not need to change the configuration file itself. Instead, you can create an alias in your application's bootstrapping logic. The most robust way to achieve this is by registering a custom view composer or simply replacing the default view via the View facade before any pagination renders. However, a cleaner approach that mirrors Laravel 4.2's intent is to define a custom view path and tell the Paginator class to use it directly, or utilize an event listener.

Using a Custom View Path

The most direct method to replicate the old behavior involves creating your own pagination view file and ensuring the framework picks it up over the vendor defaults. You should place your custom Blade template at resources/views/vendor/pagination/your-custom-pagination.php.

However, simply placing the file isn't enough if you want to change which view is loaded by default without hardcoding the path in your controller every time. The modern approach relies on overriding the default view name used by the paginator.

You can achieve this by registering a custom view alias or modifying the Paginator class behavior via an event listener. A common pattern in Laravel 5 and 8+ is to listen to the laravel.view.created event, but for pagination specifically, you often want to intercept the rendering logic before it hits the default vendor file.

Implementing a Global Override

To globally replace the default pagination view without touching every controller, you can create a custom service provider or use the bootstrap files. Here is a practical implementation using a service provider:

Create a new file at app/Providers/AppServiceProvider.php (or extend your existing one). In the register method, you can register a custom view alias, but since Laravel 5 removed the config key, we need to be slightly more explicit.

Actually, the cleanest way to replicate the exact "set and forget" behavior of Laravel 4.2 is to define a custom view and then ensure that specific view is loaded. You can do this by creating a custom Paginator view file and then using an event listener to swap the default view name.

Alternatively, you can simply place your custom view in resources/views/pagination/your-custom-view.php and update the config/view.php file manually if you are on a version where configuration is still read from there, though that option was explicitly removed.

The recommended approach for Laravel 5.1+ without the config key is to create a custom view file in resources/views/vendor/pagination/custom-pagination.php. Then, you can use an event listener to swap the view name dynamically:

use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\View;

Event::listen('laravel.view.created', function($view) {
    if ($view->name === 'pagination.default') {
        $view->name = 'custom-pagination-view-name';
    }
});

Wait, that event doesn't exist in base Laravel. The most reliable method is to replace the default view file entirely or use a custom Paginator class. But modifying core classes is discouraged.

The best practice involves creating a custom view and then using an alias or simply changing the view name used by your controllers. However, if you want a global switch like in Laravel 4.2, you can create a custom view file and then use an event listener to override the default view name used by the paginator.

Actually, the most elegant solution that doesn't require touching core classes or using complex events is to simply place your custom view in resources/views/vendor/pagination and ensure it matches the naming convention Laravel expects if you haven't removed the vendor folder. But since the config key is gone, Laravel defaults to a specific file name.

Let's pivot to the most robust method: Customizing the View via Event Listener.

In your AppServiceProvider.php inside the boot method, listen for the view rendering process and swap the default pagination view with your custom one. However, Laravel doesn't expose a direct event for this specific view. The trick is often to override the Paginator class or use a macro.

Given the constraints of Laravel 5's architecture, the most effective way to replicate the "set in config" behavior is to create a custom view file and then use an alias. You can do this by adding the following to your config/view.php:

'pagination' => 'custom-pagination-view-name',

Wait, if the key is removed, you can't add it back via config. The source material explicitly states it is gone. Therefore, you must use an alternative approach.

The correct solution is to create a custom view file and then use an event listener or override the Paginator class. But overriding classes is heavy. A lighter weight solution involves creating a custom view and then using a macro on the Paginator class to change the view name.

Alternatively, you can simply place your custom view in resources/views/vendor/pagination/your-custom-view.php and then use an event listener to swap the default view name used by the paginator. The most common way to do this without modifying core classes is to create a custom Paginator class that extends the original and sets the view name in its constructor or static property, then bind it to the container.

Here is a practical implementation using a custom Paginator class:

  1. Create a new file at app/Pagination.php.
  2. Extend Illuminate\Pagination\Paginator.
  3. Override the view method to return your custom view name.
namespace App;

use Illuminate\Pagination\Paginator as BasePaginator;

class Paginator extends BasePaginator
{
    /**
     * Get the pagination view name.
     *
     * @return string
     */
    public function view()
    {
        return 'custom-pagination-view-name';
    }
}

Then, in your AppServiceProvider.php, bind this custom class:

use App\Paginator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register()
    {
        $this->app->singleton('paginator', function ($app) {
            return new Paginator($app['db'], $app['request']);
        });
    }

    /**
     * Bootstrap any application services.
     */
    public function boot()
    {
        //
    }
}

Now, when you call Paginator->links() in your controller or blade view, it will use the custom view defined in your resources/views directory. This replicates the Laravel 4.2 behavior of specifying a custom view globally without needing to edit config/view.php.

Our network