Laravel 5 $request->input vs Input::get


Laravel 5 $request->input vs Input::get

只是想知道两者之间有什么区别:

$username = $request->input('username');

$username = Input::get('username');

没有区别,门面输入从请求调用输入方法。但是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';
    }   
}

两者都是一样的,但这种 laravel 内置功能 正确使用拉拉维尔。

您可以同时使用这两种方式,但仅在 INPUT 中进行以下操作。只是看一眼。

  1. Input::has('name')

  2. Input::all()

  3. Input::only('username', 'password')

  4. Input::except('credit_card')

  5. Input::get('products.0.name')

还有这个

Input::get('username');

这样就让事情变得容易了。

如果我们使用它,我们必须做更多的代码。

$request->input('username')

希望你能理解。谢谢。