Skip to content

Request Reference ​

query ​

Read URL query parameters:

php
$page   = $request->query('page', 1);
$search = $request->query('q');
$all    = $request->query();          // all query params as array

json ​

Read JSON request body:

php
$body  = $request->json();            // entire body as array
$name  = $request->json('name');      // single key
$page  = $request->json('page', 1);  // with default

form ​

Read application/x-www-form-urlencoded or multipart/form-data fields:

php
$name  = $request->form('name');
$all   = $request->form();            // all fields as array

body ​

Raw request body as string:

php
$raw = $request->body();

all ​

All input merged (query + body):

php
$input = $request->all();
$name  = $request->all('name');

has ​

Check if a key is present (query or body):

php
if ($request->has('search')) {
    // ...
}

files ​

Access uploaded files:

php
$file  = $request->file('avatar');        // single file
$files = $request->files();              // all files

// File properties
$file->name();        // original filename
$file->tmpPath();     // temporary file path
$file->size();        // size in bytes
$file->mimeType();    // detected MIME type
$file->extension();   // file extension

// Move to permanent location
$file->moveTo(storage_path('uploads/' . $file->name()));

Read request headers:

php
$type  = $request->header('Content-Type');
$auth  = $request->header('Authorization');
$all   = $request->headers();              // all headers as array

method ​

php
$method = $request->method(); // GET, POST, PUT, PATCH, DELETE, ...

path ​

php
$path = $request->path(); // /api/users/42

params (route parameters) ​

Route parameters are injected directly as typed method arguments:

php
$app->get('/users/{id}', function (Request $req, int $id) {
    // $id is cast to int automatically
});

ip ​

php
$ip = $request->ip(); // client IP address

isJson ​

Check if the request has a JSON body:

php
if ($request->isJson()) {
    $data = $request->json();
}

isMethod ​

php
if ($request->isMethod('POST')) {
    // ...
}

bearerToken ​

Extract Bearer token from the Authorization header:

php
$token = $request->bearerToken(); // returns string or null

Released under the MIT License.