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-hintIlluminate\Http\Request in a controller method and Laravel’s service container injects the current request instance automatically:
Using route parameters alongside the request
When a controller method also needs a route parameter, list theRequest type-hint first, then the route parameters:
Retrieving input
All input
Useall() 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:
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:Dynamic properties
You can access input values as properties directly on the request object:Subsets of input
Useonly() and except() to retrieve a subset of input:
Checking for input
Usehas() to determine whether a value is present in the request:
filled() to check that a value is present and not empty:
isNotFilled() when the value is absent or empty:
Inspecting the request
Path and URL
HTTP method
File uploads
Retrieving an uploaded file
Usefile() to retrieve an Illuminate\Http\UploadedFile instance:
hasFile():
Storing the file
Usestore() to save the file to a storage disk. The filename is generated automatically:
storeAs():
Example: handling a registration form
Next steps
Responses
Learn how to return views, redirects, and JSON from your controllers.