[英]Laravel 5 $request->input vs Input::get
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.没有区别,外观 Input 从请求中调用输入方法。 But
Input::get
is deprecated, prefer the $request->input
instead of Input::get
但
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';
}
}
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.您可以同时使用这两种方式,但以下内容仅在 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.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.