Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

inmn's avatar
Level 2

Constructors in Controllers arent supposed to use values set from Middleware, correct?

It seems it loads as:

  1. Controller:: __construct
  2. Middleware
  3. Controller::function

So - lets assume i have middleware registering an object of 'current_user'..

__construct(){
    $this->user = \App::make('current_user');
}

.. wont work; even if middleware registers a service to the container, Correct?

So i I am trying to avoid crazy cod of having to type \App::make() a thousand times, so I have simply made a function like so:

public function currentUser(){
    return \App::make('current_user');
} 

...in the controller; and in my individual controller functions simply use

$this->currentUser();

Correct?

(yeah my code works, just making sure i understand it)

0 likes
0 replies

Please or to participate in this conversation.