#Request vs $request

8 messages · Page 1 of 1 (latest)

dusk hare
#

Hi,
I have worked with Laravel for 6 months now and I still don't understand the meaning of the "Request" in controller function:

  public function store(Request $request)
    {
        $name = $request->input('name');
 
        //
    }

So, if I want to make my custom request like below I am just switching the default Request with my custom Request.
But what can I use the default Request to, I mean nothing happens if I delete it and just keep $request?

  public function store(UserControllerRequest $request)
    {
        $name = $request->input('name');
 
        //
    }
buoyant pewter
#

I don't understand your question, but what you're using is Laravel's IoC, or dependency injection. You type hint a parameter in a controller method, then Laravel will resolve that from it's container. In this case that's the current request. If you make your own request, like a FormRequest for validation, that just extends Laravels request class, so it'll inject that basically

dusk hare
#

Ok, that makes sense

#

So, use Illuminate\Http\Request is the default validation?

buoyant pewter
#

No

dusk hare
#

So a class which I can extend?

dusk hare
#

Ok, make much more sense now