You will need to replace the pagination service provider, among several other classes in the pagination library. By the sound of this, you know how to do it, but you hoped for a different answer, but since I have the code, I will pick it up here for you.
The reason you need to replace these classes / methods is because the files in Illuminate directly reference class instances in the Illuminate namespace.
In config / app.php
Replace
'Illuminate\Pagination\PaginationServiceProvider',
FROM
'ExtendedPaginationServiceProvider',
Create a new file somewhere autoloader is able to find it called ExtendedPaginationServiceProvider.php and put the following into it
<?php use Illuminate\Support\ServiceProvider; class ExtendedPaginationServiceProvider extends ServiceProvider { public function register() { $this->app->bindShared('paginator', function($app) { $paginator = new ExtendedPaginationFactory($app['request'], $app['view'], $app['translator']); $paginator->setViewName($app['config']['view.pagination']); $app->refresh('request', $paginator, 'setRequest'); return $paginator; }); } }
Create a new file somewhere autoloader can find it called ExtendedPaginationFactory.php and put the following in it
<?php use Illuminate\Pagination\Factory; class ExtendedPaginationFactory extends Factory { public function make(array $items, $total, $perPage = null) { $paginator = new ExtendedPaginationPaginator($this, $items, $total, $perPage); return $paginator->setupPaginationContext(); } }
Create a new file somewhere the autoloader can find it called ExtendedPaginationPaginator.php and put the following into it
<?php use Illuminate\Pagination\Paginator; class ExtendedPaginationPaginator extends Paginator { public function getCollection() { return new ExtendedCollection($this->items); } }
You will notice that the above returns a new instance of ExtendedCollection. Obviously replace this with your CustomCollection class, which you are referring to in your question.
To refer to others, the ExtendedCollection class might look something like the one below.
Create a new file somewhere autoloader will be able to find it with the name ExtendedCollection.php and put the following into it
<?php use Illuminate\Support\Collection; class ExtendedCollection extends Collection { }
In addition, after creating these files do not forget to run in the terminal
following:
composer dump-autoload