The Input class handles input that comes into your application via GET, POST, PUT, or DELETE requests. Retrieving input using the Input class is effortless:
$email = Input::get('email');
Note: The "get" method is used for all request types, not just GET requests.
$input = Input::get();
$input = Input::all();
By default, null will be returned if the input item does not exist. However, you may pass a different default value as a second parameter to the method:
$name = Input::get('name', 'Fred');
$name = Input::get('name', function() {return 'Fred';});
if (Input::has('name')) ...
Note: The "has" method will return false if the input item is an empty string.
$files = Input::files();
$picture = Input::file('picture');
$size = Input::file('picture.size');
Have you ever tried to re-populate an input form after an invalid form submission? It can get pretty clunky. Not in Laravel. You can easily retrieve the input from the previous request. First, you need to flash the input data to the session:
Input::flash();
Input::flash('only', array('username', 'email'));
Input::flash('except', array('password', 'credit_card'));
$name = Input::old('name');
Note: You must specify a sesion driver before using the "old" method.
Further Reading:
Since you will typically want to flash input right before a redirect, there is a beautiful shortcut for you to use:
return Redirect::to('login')->with_input();
return Redirect::to('login')->with_input('only', array('username'));
return Redirect::to('login')->with_input('except', array('password'));
Laravel provides a nice wrapper around the $_COOKIE array. However, there are a few things you should be aware of before using it. First, all Laravel cookies contain a "signature hash". This allows the framework to verify that the cookie has not been modified on the client. Secondly, when setting cookies, the cookies are not immediately sent to the browser, but are pooled until the end of the request and then sent together.
$name = Cookie::get('name');
$name = Cookie::get('name', 'Fred');
Cookie::put('name', 'Fred', 60);
Cookie::forever('name', 'Fred');
Cookie::forget('name');