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

pmall's avatar

No need to guide, create a new class, like UserManager. Put the logic to retrieve your user within it. Then inject the UserManager by type hinting it in controller / methods where you need it.

class UserManager {

    public function getUser() {
        // Your logic to fetch an user
        return $user;
    }

}
class FooController extends Controller {

    private $user;

    public function __construct(UserManager $user_manager)
    {
        $this->user = $user_manager->getUser();
    }

}
class FooFormRequest extends Request {

    public function rules(UserManager $user_manager)
    {
        $user = $user_manager->getUser();
    }

}
GuidoBelluomo's avatar

Forgive me for the immensely late response, but I was facing this exact same issue today and I found I can just get the controller resolved parameters (except dependencies & the request) by just doing this:

$this->route()->parameters()

Note that $this is a child of the standard Request class.

Previous

Please or to participate in this conversation.