Just wondering what is the difference between:
$username = $request->input('username');
and
$username = Input::get('username');
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';
}
}
Both are the same but this one kind laravel inbuilt Functionality To make a proper use of laravel.
You can use both way but following things are made only in INPUT. Just a look.
Input::has('name')
Input::all()
Input::only('username', 'password')
Input::except('credit_card')
Input::get('products.0.name')
And also this on
Input::get('username');
So that make things easy for as.
That other thing we have to do more code if we use this.
$request->input('username')
Hope You understand. Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.