Differences between input and get

1

I have a question about Laravel, what is the difference between Laravel's input and the get:

Input

public function fooFunction (Request $request){
    $request->input("foo");
}  

Get

public function fooFunction (Request $request){
    $request->get("foo");
}  

What I think is that one accesses the name of the forms and that with the other one you can also, and that the first one is little but will be deprecated, so I read in other stackoverflow post .

    
asked by CodeNoob 08.06.2017 в 21:08
source

1 answer

0

Actually there is not much difference, both methods are going to get parameters of% Symfony% co, which is nothing more than a collection of ParameterBag style elements, although the concept really comes from Doctrine.

input () is a method of the Laravel Request, which gets a parameterBag and finally uses the helper key/value of Laravel to get the desired element of that object or array.

/**
 * Retrieve an input item from the request.
 *
 * @param  string  $key
 * @param  string|array|null  $default
 * @return string|array
 */
public function input($key = null, $default = null)
{
    return data_get(
        $this->getInputSource()->all() + $this->query->all(), $key, $default
    );
}

link

get () is a Symfony HttpFoundation method, which simply allows you to get the value of any parameter of a bag .

The Laravel Request inherits the HttpFoundation method, so this method can be used as well.

/**
 * Gets a "parameter" value from any bag.
 *
 * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
 * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
 * public property instead (attributes, query, request).
 *
 * Order of precedence: PATH (routing placeholders or custom attributes), GET, BODY
 *
 * @param string $key     the key
 * @param mixed  $default the default value if the parameter key does not exist
 *
 * @return mixed
 */
public function get($key, $default = null)
{
    if ($this !== $result = $this->attributes->get($key, $this)) {
        return $result;
    }
    if ($this !== $result = $this->query->get($key, $this)) {
        return $result;
    }
    if ($this !== $result = $this->request->get($key, $this)) {
        return $result;
    }
    return $default;
}

link

    
answered by 08.06.2017 / 21:33
source