Reader Stacks

Understanding the Laravel Request Object

input(), query(), all(), and has() — the different ways to pull data off a Request, and why input() quietly merges route parameters with the query string and body.

Understanding the Laravel Request Object

Laravel wraps the incoming HTTP request in a single Illuminate\Http\Request object, available via type-hinting in a controller method or route closure, or the request() helper anywhere else.

Getting it into a controller

public function store(Request $request)
{
    $name = $request->input('name');
}

The main ways to read data

$request->input('name');          // from query string OR request body, whichever has it
$request->query('sort');          // query string only
$request->post('name');           // request body only (form-encoded/JSON)
$request->all();                  // everything as an array
$request->only(['name', 'email']); // just these keys
$request->except(['password']);    // everything except these keys
$request->has('name');             // is the key present at all
$request->filled('name');          // is the key present AND not empty

input() reads from more places than people expect

$request->input() merges route parameters, the query string, and the request body — so a value can come from any of those sources without the code making it obvious which. For a value you specifically expect from the URL query string (a filter, a sort param), $request->query() is more precise and self-documenting than the more permissive input().

has() vs filled()

has('promo_code') returns true even if the field was submitted as an empty string — it only checks presence. filled('promo_code') additionally checks that the value isn't empty. Using has() when you actually mean "was a real value provided" is a common source of bugs where an empty form field is treated as if it had content.

Getting the current path, URL, and method

$request->path();      // "products/42"
$request->fullUrl();   // full URL including query string
$request->method();    // "GET", "POST", etc.
$request->isMethod('post');

Files

$request->file('avatar');
$request->hasFile('avatar');

Validating and storing an uploaded file is covered in more depth in our file validation guide.