Support the ongoing development of Laravel.io →
posted 6 years ago

I'm getting a Too few arguments exception when trying to inject two nullable services in a controller method:

    public function home(Ordering $ordering, Newsletter $newsletter)
    {
        $this->data('ordering', $ordering);
        $this->data('newsletter', $newsletter);

        return $this->theme->view('home', $this->data);
    }

When the Ordering and Newsletter classes are resolved, it's possible for it to return null. However, in order to type-hint the classes for injection, null is not allowed. Defaulting both of the variables to null returns null for both even if they are instantiated.

How do I type-hint or inject nullable classes into my controllers?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

sephelps sephelps Joined 12 Mar 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.