4 years ago

BaseController construct dependencies

Posted 4 years ago by mikefrancis

Hi there,

Working on an app and each controller (there are a few) makes use of things like Auth and Event, so these are declared as dependencies like so:

class RegistrationController extends Controller

    protected $auth;

    public function __construct(Auth $auth) {
        $this->auth = $auth;


In the interests of keeping my code DRY I was wondering if there's a way to in App\Http\Controller to have these injected in and then I don't have to have this for every single controller.

However, if I do the above, I then cannot use parent::__construct() as I'm not passing through any dependencies.

Is there a way to achieve what I'm trying to do or should I just inject these classes for every single controller? `

Please sign in or create an account to participate in this conversation.