Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Just wondering what is the difference between:

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

and

$username = Input::get('username');
like image 822
Jonh Doe Avatar asked Feb 10 '16 13:02

Jonh Doe


1 Answers

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';
    }   
}
like image 113
Jairo Correa Avatar answered Oct 04 '22 01:10

Jairo Correa