Laravel Input Facade vs Request Facade
Yes both Facades are very similar. The reason for this is that the underlying class is the same (Illuminate\Http\Request
). You can see this by looking at both Facade classes and their accessors:
Illuminate\Support\Facades\Input
protected static function getFacadeAccessor()
{
return 'request';
}
Illuminate\Support\Facades\Request
protected static function getFacadeAccessor()
{
return 'request';
}
As you realized, one difference is the Input::get()
method. This is just "translated" to Request::input()
directly in the Facade:
public static function get($key = null, $default = null)
{
return static::$app['request']->input($key, $default);
}
Conclusion
They are essentially the same. That means, there's no need to change your existing code. However if you wanted to it wouldn't make any difference.
When writing new code you should use Request
facade, and maybe use Request::input(...)
instead of Request::get(...)
(because the former supports dot notation to access nested data, like $name = $request->input('products.0.name');
, but get
is little faster to be fair).
Input
is mentioned nowhere in the documentation for 5.0. It's not (officially) deprecated but the use ofRequest
is encouraged.
What I also really like about Request
is that the Facade actually has the name of the underlying class. This way it's clear what you're dealing with. However this can also be the root of errors. If you use something like Request::input('name')
make sure to import the Facade with use Request;
or use Illuminate\Support\Facades\Request
and not use Illuminate\Http\Request
. The opposite applies for dependency injection.
Class 'Illuminate\Support\Facades\Input' not found
if you're using less version of Laravel 5.2
In config/app.php
, replace:
'Input' => Illuminate\Support\Facades\Input::class,
Or You can import Input
facade directly as required,
use Illuminate\Support\Facades\Input;
In Laravel 5.2 Input:: is replaced with Request::
use
Request::
Add to the top of Controller or any other Class
use Illuminate\Http\Request;
In your case
$image_tmp = $request->image;
$fileName = time() . '.'.$image_tmp->clientExtension();
Laravel 6X
The Input
facade, which was primarily a duplicate of the Request
facade, has been removed. If you are using the Input::get
method, you should now call the Request::input
method. All other calls to the Input facade may simply be updated to use the Request
facade.
You can directly use $request as well
$request->all();
Difference between Request (Facade) and Illuminate\Http\Request
Straigth answer: No (particular difference)
Except that: Referencing from this source, How laravel facades work and how to use
A Laravel facade is a class which provides a static-like interface to services inside the container. These facades, according to the documentation, serve as a proxy for accessing the underlying implementation of the container’s services.
I couldn't agree more with this. But as for me, using facade pattern simply make my code cleaner :)
Laravel 7.21 Class Illuminate\Support\Facades\Input not found
Based on the Laravel docs, since version 6.x
Input
has been removed.
The Input facade, which was primarily a duplicate of the Request
facade, has been removed. If you are using theInput::get
method, you
should now call theRequest::input
method. All other calls to the
Input facade may simply be updated to use the Request facade.
Laravel Illuminate\Support\Facades\Input
<?php
use Illuminate\Support\Facades\Input;
class RegistrationController extends \BaseController {
public function __construct()
{
$this->beforeFilter('guest');
}
this controller is in global namespace. so you don't need to use use Illuminate\Support\Facades\Input;
you can directly call Input::get('foo');
<?php namespace Foo; //<---- check the namespace
use Input;
class RegistrationController extends \BaseController {
public function __construct()
{
$this->beforeFilter('guest');
}
here you can write either, use Input
or \Input::get('foo')
while calling.
How do I inject a request into a facade class in Laravel?
Looks like this worked out:
In the ParamsServiceProvider, instead of using App::bind to instantiate the Params class, do this instead:
public function register()
{
App::alias(Params::class, 'params');
}
then the request object will be injected properly into the facade.
Laravel 5 $request-input vs Input::get
There is no difference, the facade Input calls the input method from request. But Input::get
is deprecated, prefer the $request->input
instead of Input::get
<?php
namespace Illuminate\Support\Facades;
/**
* @see \Illuminate\Http\Request
*/
class Input extends Facade
{
/**
* Get an item from the input data.
*
* This method is used for all request verbs (GET, POST, PUT, and DELETE)
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function get($key = null, $default = null)
{
return static::$app['request']->input($key, $default);
}
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'request';
}
}
Related Topics
Url Querystring with a PHP Include
Phpmailer Error: Smtp -> Error: Failed to Connect to Server
Best Way to Check a Empty Array
How to Add a Condition Inside a PHP Array
Symfony: How to Refresh the Authenticated User from the Database
Codeigniter PHP Stylesheet Link. How
Get Order Increment Id in Magento
Calling PHP Function from Jquery
How to Get Results from the Wikipedia API with PHP
Laravel Collection Converts Array to Object
Strip HTML Tags and Its Contents
How to Send Email with PDF Attachment Using PHP
Upload Xls or Xlsx Files with Codeigniter, Mime-Type Error
How to Make First Letter of a Word Capital
Swap Two Words in a String PHP
How to Convert a PHP Query String into a Slash-Based Url
Parse Error: Syntax Error, Unexpected '.', Expecting ',' or ';'