Skip to main content

Documentation Index

Fetch the complete documentation index at: https://kawax.biz/llms.txt

Use this file to discover all available pages before exploring further.

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:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function store(Request $request): RedirectResponse
    {
        $name = $request->input('name');

        // Save the user...

        return redirect('/users');
    }
}
Route closures work the same way:
use Illuminate\Http\Request;

Route::get('/', function (Request $request) {
    // ...
});

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:
use App\Http\Controllers\UserController;

Route::put('/user/{id}', [UserController::class, 'update']);
public function update(Request $request, string $id): RedirectResponse
{
    // Access request data via $request, route parameter via $id

    return redirect('/users');
}

Retrieving input

All input

Use all() to retrieve all input as an array. It works for both HTML forms and XHR requests:
$input = $request->all();

A specific field

input() retrieves a value from the entire request payload, including the query string, regardless of the HTTP method:
$name = $request->input('name');
Supply a default value as the second argument:
$name = $request->input('name', 'Sally');
Access nested array input with dot notation:
$name = $request->input('products.0.name');

$names = $request->input('products.*.name');

Query string only

query() retrieves values exclusively from the query string:
$name = $request->query('name');

$name = $request->query('name', 'Helen');

// All query string values as an array
$query = $request->query();
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:
// Returns a Stringable instance
$name = $request->string('name')->trim();

// Returns an integer
$perPage = $request->integer('per_page');

// Returns a boolean ("1", "true", "on", "yes" all become true)
$archived = $request->boolean('archived');

// Returns an array
$versions = $request->array('versions');

// Returns a Carbon instance
$birthday = $request->date('birthday');

Dynamic properties

You can access input values as properties directly on the request object:
$name = $request->name;
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:
$input = $request->only(['username', 'password']);

$input = $request->except(['credit_card']);

Checking for input

Use has() to determine whether a value is present in the request:
if ($request->has('name')) {
    // ...
}

// Check that all specified keys are present
if ($request->has(['name', 'email'])) {
    // ...
}
Use filled() to check that a value is present and not empty:
if ($request->filled('name')) {
    // ...
}
Use isNotFilled() when the value is absent or empty:
if ($request->isNotFilled('name')) {
    // ...
}

Inspecting the request

Path and URL

// Retrieve the path (e.g. "foo/bar")
$uri = $request->path();

// Test the path against a pattern (* wildcard supported)
if ($request->is('admin/*')) {
    // ...
}

// Test against a named route
if ($request->routeIs('admin.*')) {
    // ...
}

// Full URL without the query string
$url = $request->url();

// Full URL including the query string
$urlWithQueryString = $request->fullUrl();

HTTP method

$method = $request->method();

if ($request->isMethod('post')) {
    // Only process POST requests
}

File uploads

Retrieving an uploaded file

Use file() to retrieve an Illuminate\Http\UploadedFile instance:
$file = $request->file('photo');

// Or as a dynamic property
$file = $request->photo;
Check that a file was actually uploaded with hasFile():
if ($request->hasFile('photo')) {
    // ...
}

Storing the file

Use store() to save the file to a storage disk. The filename is generated automatically:
// Store in the "images" directory on the default disk
$path = $request->photo->store('images');

// Store on S3
$path = $request->photo->store('images', 's3');
To specify a filename, use storeAs():
$path = $request->photo->storeAs('images', 'filename.jpg');
Always validate the file type and size when accepting uploads. Use Laravel’s validation rules to handle this safely.

Example: handling a registration form

<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class RegisterController extends Controller
{
    public function store(Request $request): RedirectResponse
    {
        // Retrieve individual fields
        $name = $request->input('name');
        $email = $request->input('email');

        // Or retrieve only the fields you need
        $data = $request->only(['name', 'email', 'password']);

        // Create the user...

        return redirect('/dashboard');
    }
}
Define the corresponding route:
use App\Http\Controllers\RegisterController;

Route::post('/register', [RegisterController::class, 'store']);

Next steps

Responses

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