There are actually two classes at play here:
Where the Factory
class actually orchestrates the creation of Paginator
instances. After a quick glance, I couldn't really tell you why the Factory
class is in charge of get/setPageName()
, but that's where they live.
It seems that you would need two distinct Factory
instances, which, fortunately, is possible via the IoC Container. Since the PaginationServiceProvider
binds to paginator
, calling $app->make("Illuminate\Pagination\Factory")
twice should generate two distinct factories. If you're using namespaces, a service provider to inject the factories into your controller might look like:
class DoublyPaginatedControllerServiceProvider extends ServiceProvider {
public function register($app)
{
$this->bindShared('paginator.photos', function ($app) {
$factory = $app->make('Illuminate\Pagination\Factory');
$factory->setPageName('photoPage');
return $factory;
});
$this->bindShared('paginator.comments', function ($app) {
$factory = $app->make('Illuminate\Pagination\Factory');
$factory->setPageName('commentPage');
return $factory;
});
$this->app->bindShared('Namespace\DoublyPaginatedController', function ($app) {
return new DoublyPaginatedController(
$app['paginator.photos'],
$app['paginator.comments']
);
}
}
}
Of course, the downside here is that you can't use Eloquent's Model::paginate()
-- you'd need to manually determine which set of items to get and pass them to each Factory's make()
method.