HTTP Requests

Obtaining A Request Instance

Via Facade

The Request facade will grant you access to the current request that is bound in the container. For example:

$name = Request::input('name');

Remember, if you are in a namespace, you will have to import the Request facade using a use Request; statement at the top of your class file.

Via Dependency Injection

To obtain an instance of the current HTTP request via dependency injection, you should type-hint the class on your controller constructor or method. The current request instance will automatically be injected by the service container:

Retrieving Input

Retrieving An Input Value

Using a few simple methods, you may access all user input from your Illuminate\Http\Request instance. You do not need to worry about the HTTP verb used for the request, as input is accessed in the same way for all verbs.

Creating A Cookie That Lasts Forever*

Files

Retrieving An Uploaded File

$file = Request::file('photo');

Determining If A File Was Uploaded

if (Request::hasFile('photo'))
{
//
}

The object returned by the file method is an instance of the Symfony\Component\HttpFoundation\File\UploadedFile class, which extends the PHP SplFileInfo class and provides a variety of methods for interacting with the file.