I'm trying to use $input->all()
as opposed to Input::all()
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?
Getting Only Some Of The Request Input$input = Input::only('username', 'password'); $input = Input::except('credit_card'); When working on forms with "array" inputs, you may use dot notation to access the arrays: $input = Input::get('products.0.name');
Introduction. Laravel's Illuminate\Http\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.
The “path” method is used to retrieve the requested URI. The is method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method.
The has MethodThe $request->has() method will now return true even if the input value is an empty string or null . A new $request->filled() method has been added that provides the previous behaviour of the has() method. The $request->exists() method still works, it is just an alias for $request->has() .
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: https://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.
One more important thing about using Request or Input to access the User Input is the version of Laravel that you are using.
In the Laravel 4.2 and prior, you could have access the Input::all(), Input::get() but from Laravel 5 onwards, it's been suggested to use the Input via Request facade
Ref: https://laravel.com/docs/5.2/requests
In case if you want to make use of Input in Laravel 5.0 and onwards, then you need to add this facade in the config/app.php file under the aliases section as 'Input' => Illuminate\Support\Facades\Input::class
Once you add the facade under alias, you should start using the 'Input::all()'
Hope this helps some others, who are having the confusion as whether to use 'Input' or 'Request' for Laravel 5.0 onwards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With