Laravel 5 $request->input vs Input::get
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35316302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 $request->input vs Input::get
提问by Jonh Doe
Just wondering what is the difference between:
只是想知道两者之间有什么区别:
$username = $request->input('username');
and
和
$username = Input::get('username');
回答by Jairo Correa
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
没有区别,外观 Input 从请求中调用输入方法。但Input::get
已弃用,更喜欢$request->input
而不是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';
}
}
回答by Yagnik Detroja
Both are the same but this one kind laravel inbuilt Functionality To make a proper use of laravel.
两者都是相同的,但是这种 laravel 内置功能可以正确使用 laravel。
You can use both way but following things are made only in INPUT. Just a look.
您可以同时使用这两种方式,但以下内容仅在 INPUT 中进行。只是看一眼。
Input::has('name')
Input::all()
Input::only('username', 'password')
Input::except('credit_card')
Input::get('products.0.name')
输入::已('名称')
输入::全部()
输入::仅('用户名','密码')
输入::除了('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.
希望你能理解。谢谢。