Support the ongoing development of Laravel.io →
Requests IOC

Hello!

I there way to use one controller class but for different routes? I mean, one controller class but with different parameters in constructor.

I tryied to do something like that:

App::bind('cats_controller', function () {
    return new AnimalController(App::make('CatRepository'));
});
App::bind('dogs_controller', function () {
    return new AnimalController(App::make('DogRepository'));
});

# routes.php
Route:controller('cats', 'cats_controller');
Route:controller('dogs', 'dogs_controller');

But it didn't actually work.

There is, ofcourse a variant with inheritance, but is there way to make it without it?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

violarium violarium Joined 12 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.