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