Skip to content

Request Class

The Request class represents the current HTTP request.

Properties

PropertyTypeDescription
methodstringHTTP method (GET, POST, etc.)
pathstringRequest path
queryarrayGET parameters
bodyarrayPOST parameters
jsonarrayJSON request body
headersarrayRequest headers
cookiesarrayCookie values
filesarrayUploaded files
ipstringClient IP address

Methods

Parameter Access

php
$id = $request->param('id');           // Route parameter
$email = $request->input('email');      // POST/GET/JSON input
$name = $request->input('name', 'default');
$all = $request->all();                  // All input
$only = $request->only(['name', 'email']);
$except = $request->except(['password']);

Checks

php
if ($request->has('email')) { ... }
if ($request->filled('email')) { ... }
if ($request->missing('email')) { ... }
if ($request->isJson()) { ... }
if ($request->wantsJson()) { ... }
if ($request->isMethod('POST')) { ... }

Authentication

php
$token = $request->bearerToken();
$user = $request->user();
if ($request->isAuthenticated()) { ... }

CSRF Protection

php
if (!$request->validateCsrf()) {
    return Response::error('Invalid CSRF token', 419);
}

Session

php
$value = $request->session('key');
$all = $request->session();

Helpers

php
$ip = $request->getClientIp();
$ua = $request->getUserAgent();
$url = $request->isSecure();
$path = $request->path;

Released under the MIT License.