V4n1ll4 V4n1ll4 - 10 months ago 56
PHP Question

Using $input->all() instead of Input::all() Laravel-5

I'm trying to use

as opposed to
in Laravel-5, however it doesn't seem to like it, even though I am passing the Input reference to the function, like so:

* Search for a specified resource.
* @return Response
public function search(Booking $booking, Input $input)
dd($input->all()); // this doesn't work

dd(Input::all()); // this DOES work


The error I get is:

Call to undefined method Illuminate\Support\Facades\Input::all()

Does anyone have a solution to this problem?


I don't think you're supposed to inject Facades into your Controllers. Input is a facade for Illuminate\Http\Request and it's service container binding is request. So according to the documentation, in Laravel 5 you can do Request::all() and in Laravel 5.1 you can do $request->all()

http://laravel.com/docs/5.0/requests#retrieving-input http://laravel.com/docs/5.1/requests#retrieving-input

EDIT: This post gives some more in-depth information: http://stackoverflow.com/a/29961400/2433843

EDIT3: I think it would be great if someone could explain WHY exactly you can't inject Facades into your Controllers. I understand DI and Facades are two different things entirely, and L5+ is pushing the developers towards DI. I just don't exactly understand why injecting a facade wouldn't work, since it points towards another class, and it works when you do not inject it. Not to forget Facades and Aliases are two seperate things too. I hope someone can elaborate on this.