Skip to main content

The Request object

Illuminate\Http\Request provides an object-oriented interface for working with the current HTTP request. Through it you can access form data, query strings, uploaded files, headers, and more.

Injecting the request into controllers

Type-hint Illuminate\Http\Request in a controller method and Laravel’s service container injects the current request instance automatically:
Route closures work the same way:

Using route parameters alongside the request

When a controller method also needs a route parameter, list the Request type-hint first, then the route parameters:

Retrieving input

All input

Use all() to retrieve all input as an array. It works for both HTML forms and XHR requests:

A specific field

input() retrieves a value from the entire request payload, including the query string, regardless of the HTTP method:
Supply a default value as the second argument:
Access nested array input with dot notation:

Query string only

query() retrieves values exclusively from the query string:
input() searches both the request body and the query string, while query() only searches the query string. Use query() when you need to distinguish between POST data and URL parameters.

Typed retrieval

Laravel provides helpers to retrieve input already cast to a specific type:

Strictly typed retrieval

The string, integer, float and boolean methods cast the incoming input to that type. For example, ?count=abc is cast to 0 by the integer method, and ?name[]=taylor causes an “Array to string conversion” error in the string method. If you want to receive a default value instead of casting when the input is not of the expected type, pass strict: true.
In strict mode, integer and float return the default value when the input is not a valid integer or number, string returns the default value when the input is not a string or number, and boolean returns the default value when the input is not one of 1, true, on, yes, 0, false, off or no.

Retrieving UUIDs and ULIDs

You can retrieve input values that contain a UUID or ULID with the uuid and ulid methods. uuid returns a Ramsey\Uuid\UuidInterface instance, and ulid returns a Symfony\Component\Uid\Ulid instance. If no input value exists with the given name, null is returned.
If the input value exists but is not a valid UUID or ULID, an InvalidArgumentException is thrown. We therefore recommend validating the input before calling these methods.

Retrieving model input

When using form requests, you can retrieve Eloquent models using identifiers contained in the request input. The model method returns null when the input is empty or no matching record exists, while the modelOrFail method throws an Illuminate\Database\Eloquent\ModelNotFoundException. When the input value is an array of identifiers, the models method returns an Eloquent collection of the matching records.
If you omit the model class, Laravel infers the class from the input key. It strips the _id or _ids suffix and converts the remaining name to singular studly case. The model is resolved from your application’s Models namespace, falling back to the application’s root namespace when no matching model exists there.
You may also pass a closure to constrain the query used to retrieve the model. The closure receives an Eloquent query builder instance, and its conditions are grouped before the identifier from the request input is applied. Pass the closure as the second argument, or as the third argument after an explicit model class.

Dynamic properties

You can access input values as properties directly on the request object:
Dynamic properties first search the request payload, then fall back to route parameters if nothing is found.

Subsets of input

Use only() and except() to retrieve a subset of input:

Checking for input

Use has() to determine whether a value is present in the request:
Use filled() to check that a value is present and not empty:
Use isNotFilled() when the value is absent or empty:

Inspecting the request

Path and URL

HTTP method

Retrieving request headers

Retrieving a header

Use the header method to retrieve a request header. If the header is not present, null is returned. You may pass a second argument to specify a default value to return when the header is missing.
Use the hasHeader method to check whether the request contains a given header.

Retrieving a bearer token

To retrieve a bearer token from the Authorization header, use the bearerToken method. If no token is present, null is returned.

File uploads

Retrieving an uploaded file

Use file() to retrieve an Illuminate\Http\UploadedFile instance:
Check that a file was actually uploaded with hasFile():

Storing the file

Use store() to save the file to a storage disk. The filename is generated automatically:
To specify a filename, use storeAs():
Always validate the file type and size when accepting uploads. Use Laravel’s validation rules to handle this safely.

Example: handling a registration form

Define the corresponding route:

Configuring trusted hosts

By default, Laravel responds to every request it receives, regardless of the content of the HTTP request’s Host header. The Host header’s value is also used when generating absolute URLs to your application during a web request. Typically, you configure your web server, such as Nginx or Apache, to send only requests matching a given hostname to your application. If you can’t customize your web server directly and need to tell Laravel to respond only to certain hostnames, enable the Illuminate\Http\Middleware\TrustHosts middleware. To enable the TrustHosts middleware, call the trustHosts method in bootstrap/app.php. Use the at argument to specify the hostnames your application should respond to. Hostname strings are treated as regular expressions, and requests with any other Host header are rejected.
By default, requests coming from subdomains of the application’s URL are also trusted automatically. To disable this behavior, use the subdomains argument.
If you need your application’s configuration files or database to determine the trusted hosts, you can pass a closure to the at argument.
If you only need to trust your application’s own host, you can omit the at argument. In that case, the host defined in the app.url configuration value and all of its subdomains are trusted.
To trust only the host defined in app.url and not its subdomains, pass false to the subdomains argument.

Next steps

Responses

Learn how to return views, redirects, and JSON from your controllers.
Last modified on November 28, 2026