Documentation

FormRequest extends Request
in package
implements ValidatesWhenResolved Uses ValidatesWhenResolvedTrait

Request represents an HTTP request.

The methods dealing with URL accept / return a raw path (% encoded):

  • getBasePath
  • getBaseUrl
  • getPathInfo
  • getRequestUri
  • getUri
  • getUriForPath

Interfaces, Classes and Traits

ValidatesWhenResolved

Table of Contents

HEADER_CLIENT_HOST  = self::HEADER_X_FORWARDED_HOST
HEADER_CLIENT_IP  = self::HEADER_X_FORWARDED_FOR
HEADER_CLIENT_PORT  = self::HEADER_X_FORWARDED_PORT
HEADER_CLIENT_PROTO  = self::HEADER_X_FORWARDED_PROTO
HEADER_FORWARDED  = 0b1
HEADER_X_FORWARDED_ALL  = 0b11110
HEADER_X_FORWARDED_AWS_ELB  = 0b11010
HEADER_X_FORWARDED_FOR  = 0b10
HEADER_X_FORWARDED_HOST  = 0b100
HEADER_X_FORWARDED_PORT  = 0b10000
HEADER_X_FORWARDED_PROTO  = 0b1000
METHOD_CONNECT  = 'CONNECT'
METHOD_DELETE  = 'DELETE'
METHOD_GET  = 'GET'
METHOD_HEAD  = 'HEAD'
METHOD_OPTIONS  = 'OPTIONS'
METHOD_PATCH  = 'PATCH'
METHOD_POST  = 'POST'
METHOD_PURGE  = 'PURGE'
METHOD_PUT  = 'PUT'
METHOD_TRACE  = 'TRACE'
$attributes  : ParameterBag
Custom parameters.
$cookies  : ParameterBag
Cookies ($_COOKIE).
$files  : FileBag
Uploaded files ($_FILES).
$headers  : HeaderBag
Headers (taken from the $_SERVER).
$query  : ParameterBag
Query string parameters ($_GET).
$request  : ParameterBag
Request body parameters ($_POST).
$server  : ServerBag
Server and execution environment parameters ($_SERVER).
$acceptableContentTypes  : array<string|int, mixed>
$basePath  : string
$baseUrl  : string
$charsets  : array<string|int, mixed>
$container  : Container
The container instance.
$content  : string|resource|false|null
$convertedFiles  : array<string|int, mixed>
All of the converted files for the request.
$defaultLocale  : string
$encodings  : array<string|int, mixed>
$errorBag  : string
The key to be used for the view error bag.
$format  : string
$formats  : array<string|int, mixed>
$httpMethodParameterOverride  : mixed
$json  : ParameterBag|null
The decoded JSON content for the request.
$languages  : array<string|int, mixed>
$locale  : string
$macros  : array<string|int, mixed>
The registered string macros.
$method  : string
$pathInfo  : string
$redirect  : string
The URI to redirect to if validation fails.
$redirectAction  : string
The controller action to redirect to if validation fails.
$redirector  : Redirector
The redirector instance.
$redirectRoute  : string
The route to redirect to if validation fails.
$requestFactory  : mixed
$requestUri  : string
$routeResolver  : Closure
The route resolver callback.
$session  : SessionInterface
$trustedHeaders  : mixed
Names for headers that can be trusted when using trusted proxies.
$trustedHostPatterns  : array<string|int, string>
$trustedHosts  : array<string|int, string>
$trustedProxies  : array<string|int, string>
$userResolver  : Closure
The user resolver callback.
$forwardedParams  : mixed
$isForwardedValid  : mixed
$isHostValid  : mixed
$trustedHeaderNames  : mixed
$trustedHeaderSet  : mixed
__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__clone()  : mixed
Clones the current request.
__construct()  : mixed
__get()  : mixed
Get an input element from the request.
__isset()  : bool
Check if an input element is set on the request.
__toString()  : string
Returns the request as a string.
accepts()  : bool
Determines whether the current requests accepts a given content type.
acceptsHtml()  : bool
Determines whether a request accepts HTML.
acceptsJson()  : bool
Determines whether a request accepts JSON.
ajax()  : bool
Determine if the request is the result of an AJAX call.
all()  : array<string|int, mixed>
Get all of the input and files for the request.
allFiles()  : array<string|int, mixed>
Get an array of all of the files on the request.
attributes()  : array<string|int, mixed>
Get custom attributes for validator errors.
bearerToken()  : string|null
Get the bearer token from the request headers.
capture()  : static
Create a new Illuminate HTTP request from server variables.
cookie()  : string|array<string|int, mixed>
Retrieve a cookie from the request.
create()  : static
Creates a Request based on a given URI and configuration.
createFromBase()  : Request
Create an Illuminate request from a Symfony instance.
createFromGlobals()  : static
Creates a new request with values from PHP's super globals.
decodedPath()  : string
Get the current decoded path info for the request.
duplicate()  : static
Clones a request and overrides some of its parameters.
enableHttpMethodParameterOverride()  : mixed
Enables support for the _method request parameter to determine the intended HTTP method.
except()  : array<string|int, mixed>
Get all of the input except for a specified array of items.
exists()  : bool
Determine if the request contains a given input item key.
expectsJson()  : bool
Determine if the current request probably expects a JSON response.
file()  : UploadedFile|array<string|int, mixed>|null
Retrieve a file from the request.
filled()  : bool
Determine if the request contains a non-empty value for an input item.
fingerprint()  : string
Get a unique fingerprint for the request / route / IP address.
flash()  : void
Flash the input for the current request to the session.
flashExcept()  : void
Flash only some of the input to the session.
flashOnly()  : void
Flash only some of the input to the session.
flush()  : void
Flush all of the old input from the session.
format()  : string
Get the data format expected in the response.
fullUrl()  : string
Get the full URL for the request.
fullUrlIs()  : bool
Determine if the current request URL and query string matches a pattern.
fullUrlWithQuery()  : string
Get the full URL for the request with the added query string parameters.
get()  : mixed
Gets a "parameter" value from any bag.
getAcceptableContentTypes()  : array<string|int, mixed>
Gets a list of content types acceptable by the client browser.
getBasePath()  : string
Returns the root path from which this request is executed.
getBaseUrl()  : string
Returns the root URL from which this request is executed.
getCharsets()  : array<string|int, mixed>
Gets a list of charsets acceptable by the client browser.
getClientIp()  : string|null
Returns the client IP address.
getClientIps()  : array<string|int, mixed>
Returns the client IP addresses.
getContent()  : string|resource
Returns the request body content.
getContentType()  : string|null
Gets the format associated with the request.
getDefaultLocale()  : string
Get the default locale.
getEncodings()  : array<string|int, mixed>
Gets a list of encodings acceptable by the client browser.
getETags()  : array<string|int, mixed>
Gets the Etags.
getFormat()  : string|null
Gets the format associated with the mime type.
getHost()  : string
Returns the host name.
getHttpHost()  : string
Returns the HTTP host being requested.
getHttpMethodParameterOverride()  : bool
Checks whether support for the _method request parameter is enabled.
getLanguages()  : array<string|int, mixed>
Gets a list of languages acceptable by the client browser.
getLocale()  : string
Get the locale.
getMethod()  : string
Gets the request "intended" method.
getMimeType()  : string|null
Gets the mime type associated with the format.
getMimeTypes()  : array<string|int, mixed>
Gets the mime types associated with the format.
getPassword()  : string|null
Returns the password.
getPathInfo()  : string
Returns the path being requested relative to the executed script.
getPort()  : int|string
Returns the port on which the request is made.
getPreferredLanguage()  : string|null
Returns the preferred language.
getProtocolVersion()  : string
Returns the protocol version.
getQueryString()  : string|null
Generates the normalized query string for the Request.
getRealMethod()  : string
Gets the "real" request method.
getRelativeUriForPath()  : string
Returns the path as relative reference from the current Request path.
getRequestFormat()  : string|null
Gets the request format.
getRequestUri()  : string
Returns the requested URI (path and query string).
getRouteResolver()  : Closure
Get the route resolver callback.
getScheme()  : string
Gets the request's scheme.
getSchemeAndHttpHost()  : string
Gets the scheme and HTTP host.
getScriptName()  : string
Returns current script name.
getSession()  : SessionInterface|null
Gets the Session.
getTrustedHeaderName()  : string
Gets the trusted proxy header name.
getTrustedHeaderSet()  : int
Gets the set of trusted headers from trusted proxies.
getTrustedHosts()  : array<string|int, mixed>
Gets the list of trusted host patterns.
getTrustedProxies()  : array<string|int, mixed>
Gets the list of trusted proxies.
getUri()  : string
Generates a normalized URI (URL) for the Request.
getUriForPath()  : string
Generates a normalized URI for the given path.
getUser()  : string|null
Returns the user.
getUserInfo()  : string
Gets the user info.
getUserResolver()  : Closure
Get the user resolver callback.
has()  : bool
Determine if the request contains a given input item key.
hasAny()  : bool
Determine if the request contains any of the given inputs.
hasCookie()  : bool
Determine if a cookie is set on the request.
hasFile()  : bool
Determine if the uploaded data contains a file.
hasHeader()  : bool
Determine if a header is set on the request.
hasMacro()  : bool
Checks if macro is registered.
hasPreviousSession()  : bool
Whether the request contains a Session which was started in one of the previous requests.
hasSession()  : bool
Whether the request contains a Session object.
header()  : string|array<string|int, mixed>
Retrieve a header from the request.
initialize()  : mixed
Sets the parameters for this request.
input()  : string|array<string|int, mixed>
Retrieve an input item from the request.
instance()  : $this
Return the Request instance.
ip()  : string
Get the client IP address.
ips()  : array<string|int, mixed>
Get the client IP addresses.
is()  : bool
Determine if the current request URI matches a pattern.
isFromTrustedProxy()  : bool
Indicates whether this request originated from a trusted proxy.
isJson()  : bool
Determine if the request is sending JSON.
isMethod()  : bool
Checks if the request method is of specified type.
isMethodCacheable()  : bool
Checks whether the method is cacheable or not.
isMethodIdempotent()  : bool
Checks whether or not the method is idempotent.
isMethodSafe()  : bool
Checks whether or not the method is safe.
isNoCache()  : bool
isSecure()  : bool
Checks whether the request is secure or not.
isXmlHttpRequest()  : bool
Returns true if the request is a XMLHttpRequest.
json()  : ParameterBag|mixed
Get the JSON payload for the request.
keys()  : array<string|int, mixed>
Get the keys for all of the input and files.
macro()  : void
Register a custom macro.
matchesType()  : bool
Determine if the given content types match.
merge()  : Request
Merge new input into the current request's input array.
messages()  : array<string|int, mixed>
Get custom messages for validator errors.
method()  : string
Get the request method.
mixin()  : void
Mix another object into the class.
normalizeQueryString()  : string
Normalizes a query string.
offsetExists()  : bool
Determine if the given offset exists.
offsetGet()  : mixed
Get the value at the given offset.
offsetSet()  : void
Set the value at the given offset.
offsetUnset()  : void
Remove the value at the given offset.
old()  : string|array<string|int, mixed>
Retrieve an old input item.
only()  : array<string|int, mixed>
Get a subset containing the provided keys with values from the input data.
overrideGlobals()  : mixed
Overrides the PHP global variables according to this request instance.
path()  : string
Get the current path info for the request.
pjax()  : bool
Determine if the request is the result of an PJAX call.
post()  : string|array<string|int, mixed>
Retrieve a request payload item from the request.
prefers()  : string|null
Return the most suitable content type from the given array based on content negotiation.
query()  : string|array<string|int, mixed>
Retrieve a query string item from the request.
replace()  : Request
Replace the input for the current request.
root()  : string
Get the root URL for the application.
route()  : Route|object|string
Get the route handling the request.
routeIs()  : bool
Determine if the route name matches a given pattern.
secure()  : bool
Determine if the request is over HTTPS.
segment()  : string|null
Get a segment from the URI (1 based index).
segments()  : array<string|int, mixed>
Get all of the segments for the request path.
server()  : string|array<string|int, mixed>
Retrieve a server variable from the request.
session()  : Store
Get the session associated with the request.
setContainer()  : $this
Set the container implementation.
setDefaultLocale()  : mixed
Sets the default locale.
setFactory()  : mixed
Sets a callable able to create a Request instance.
setFormat()  : mixed
Associates a format with mime types.
setJson()  : $this
Set the JSON payload for the request.
setLaravelSession()  : void
Set the session instance on the request.
setLocale()  : mixed
Sets the locale.
setMethod()  : mixed
Sets the request method.
setRedirector()  : $this
Set the Redirector instance.
setRequestFormat()  : mixed
Sets the request format.
setRouteResolver()  : $this
Set the route resolver callback.
setSession()  : mixed
Sets the Session.
setTrustedHeaderName()  : mixed
Sets the name for trusted headers.
setTrustedHosts()  : mixed
Sets a list of trusted host patterns.
setTrustedProxies()  : mixed
Sets a list of trusted proxies.
setUserResolver()  : $this
Set the user resolver callback.
toArray()  : array<string|int, mixed>
Get all of the input and files for the request.
url()  : string
Get the URL (no query string) for the request.
user()  : mixed
Get the user making the request.
userAgent()  : string
Get the client user agent.
validate()  : void
Validate the class instance.
validated()  : array<string|int, mixed>
Get the validated data from the request.
wantsJson()  : bool
Determine if the current request is asking for JSON in return.
convertUploadedFiles()  : array<string|int, mixed>
Convert the given array of Symfony UploadedFiles to custom Laravel UploadedFiles.
createDefaultValidator()  : Validator
Create the default validator instance.
failedAuthorization()  : void
Handle a failed authorization attempt.
failedValidation()  : void
Handle a failed validation attempt.
filterFiles()  : mixed
Filter the given array of files, removing any empty values.
getInputSource()  : ParameterBag
Get the input source for the request.
getRedirectUrl()  : string
Get the URL to redirect to on a validation error.
getValidatorInstance()  : Validator
Get the validator instance for the request.
initializeFormats()  : mixed
Initializes HTTP request formats.
isEmptyString()  : bool
Determine if the given input key is an empty string for "has".
isValidFile()  : bool
Check that the given file is a valid file instance.
passesAuthorization()  : bool
Determine if the request passes the authorization check.
prepareBasePath()  : string
Prepares the base path.
prepareBaseUrl()  : string
Prepares the base URL.
prepareForValidation()  : void
Prepare the data for validation.
preparePathInfo()  : string
Prepares the path info.
prepareRequestUri()  : mixed
retrieveItem()  : string|array<string|int, mixed>
Retrieve a parameter item from a given source.
validationData()  : array<string|int, mixed>
Get data to be validated from the request.
createRequestFromFactory()  : mixed
getTrustedValues()  : mixed
getUrlencodedPrefix()  : string|false
Returns the prefix as encoded in the string when the string starts with the given prefix, false otherwise.
normalizeAndFilterClientIps()  : mixed
setPhpDefaultLocale()  : mixed
Sets the default PHP locale.

Constants

HEADER_CLIENT_HOST

public mixed HEADER_CLIENT_HOST = self::HEADER_X_FORWARDED_HOST
Tags
deprecated

since version 3.3, to be removed in 4.0

HEADER_CLIENT_IP

public mixed HEADER_CLIENT_IP = self::HEADER_X_FORWARDED_FOR
Tags
deprecated

since version 3.3, to be removed in 4.0

HEADER_CLIENT_PORT

public mixed HEADER_CLIENT_PORT = self::HEADER_X_FORWARDED_PORT
Tags
deprecated

since version 3.3, to be removed in 4.0

HEADER_CLIENT_PROTO

public mixed HEADER_CLIENT_PROTO = self::HEADER_X_FORWARDED_PROTO
Tags
deprecated

since version 3.3, to be removed in 4.0

HEADER_FORWARDED

public mixed HEADER_FORWARDED = 0b1

HEADER_X_FORWARDED_ALL

public mixed HEADER_X_FORWARDED_ALL = 0b11110

HEADER_X_FORWARDED_AWS_ELB

public mixed HEADER_X_FORWARDED_AWS_ELB = 0b11010

HEADER_X_FORWARDED_FOR

public mixed HEADER_X_FORWARDED_FOR = 0b10

HEADER_X_FORWARDED_HOST

public mixed HEADER_X_FORWARDED_HOST = 0b100

HEADER_X_FORWARDED_PORT

public mixed HEADER_X_FORWARDED_PORT = 0b10000

HEADER_X_FORWARDED_PROTO

public mixed HEADER_X_FORWARDED_PROTO = 0b1000

METHOD_CONNECT

public mixed METHOD_CONNECT = 'CONNECT'

METHOD_DELETE

public mixed METHOD_DELETE = 'DELETE'

METHOD_GET

public mixed METHOD_GET = 'GET'

METHOD_HEAD

public mixed METHOD_HEAD = 'HEAD'

METHOD_OPTIONS

public mixed METHOD_OPTIONS = 'OPTIONS'

METHOD_PATCH

public mixed METHOD_PATCH = 'PATCH'

METHOD_POST

public mixed METHOD_POST = 'POST'

METHOD_PURGE

public mixed METHOD_PURGE = 'PURGE'

METHOD_PUT

public mixed METHOD_PUT = 'PUT'

METHOD_TRACE

public mixed METHOD_TRACE = 'TRACE'

Properties

$server

Server and execution environment parameters ($_SERVER).

public ServerBag $server

$acceptableContentTypes

protected array<string|int, mixed> $acceptableContentTypes

$basePath

protected string $basePath

$charsets

protected array<string|int, mixed> $charsets

$content

protected string|resource|false|null $content

$convertedFiles

All of the converted files for the request.

protected array<string|int, mixed> $convertedFiles

$defaultLocale

protected string $defaultLocale = 'en'

$encodings

protected array<string|int, mixed> $encodings

$errorBag

The key to be used for the view error bag.

protected string $errorBag = 'default'

$formats

protected static array<string|int, mixed> $formats

$httpMethodParameterOverride

protected static mixed $httpMethodParameterOverride = false

$languages

protected array<string|int, mixed> $languages

$macros

The registered string macros.

protected static array<string|int, mixed> $macros = []

$pathInfo

protected string $pathInfo

$redirect

The URI to redirect to if validation fails.

protected string $redirect

$redirectAction

The controller action to redirect to if validation fails.

protected string $redirectAction

$redirectRoute

The route to redirect to if validation fails.

protected string $redirectRoute

$requestFactory

protected static mixed $requestFactory

$requestUri

protected string $requestUri

$routeResolver

The route resolver callback.

protected Closure $routeResolver

$trustedHeaders

Names for headers that can be trusted when using trusted proxies.

protected static mixed $trustedHeaders = [self::HEADER_FORWARDED => 'FORWARDED', self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT']

The FORWARDED header is the standard as of rfc7239.

The other headers are non-standard, but widely used by popular reverse proxies (like Apache mod_proxy or Amazon EC2).

Tags
deprecated

since version 3.3, to be removed in 4.0

$trustedHostPatterns

protected static array<string|int, string> $trustedHostPatterns = []

$trustedHosts

protected static array<string|int, string> $trustedHosts = []

$trustedProxies

protected static array<string|int, string> $trustedProxies = []

$userResolver

The user resolver callback.

protected Closure $userResolver

$forwardedParams

private static mixed $forwardedParams = [self::HEADER_X_FORWARDED_FOR => 'for', self::HEADER_X_FORWARDED_HOST => 'host', self::HEADER_X_FORWARDED_PROTO => 'proto', self::HEADER_X_FORWARDED_PORT => 'host']

$isForwardedValid

private mixed $isForwardedValid = true

$isHostValid

private mixed $isHostValid = true

$trustedHeaderNames

private static mixed $trustedHeaderNames = [self::HEADER_FORWARDED => 'FORWARDED', self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT']
Tags
deprecated

since version 3.3, to be removed in 4.0

$trustedHeaderSet

private static mixed $trustedHeaderSet = -1

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
mixed

__clone()

Clones the current request.

public __clone() : mixed

Note that the session is not cloned as duplicated requests are most of the time sub-requests of the main one.

Return values
mixed

__construct()

public __construct([array<string|int, mixed> $query = [] ][, array<string|int, mixed> $request = [] ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string|resource|null $content = null ]) : mixed
Parameters
$query : array<string|int, mixed> = []

The GET parameters

$request : array<string|int, mixed> = []

The POST parameters

$attributes : array<string|int, mixed> = []

The request attributes (parameters parsed from the PATH_INFO, ...)

$cookies : array<string|int, mixed> = []

The COOKIE parameters

$files : array<string|int, mixed> = []

The FILES parameters

$server : array<string|int, mixed> = []

The SERVER parameters

$content : string|resource|null = null

The raw body data

Return values
mixed

__get()

Get an input element from the request.

public __get(string $key) : mixed
Parameters
$key : string
Return values
mixed

__isset()

Check if an input element is set on the request.

public __isset(string $key) : bool
Parameters
$key : string
Return values
bool

__toString()

Returns the request as a string.

public __toString() : string
Return values
string

The request

accepts()

Determines whether the current requests accepts a given content type.

public accepts(string|array<string|int, mixed> $contentTypes) : bool
Parameters
$contentTypes : string|array<string|int, mixed>
Return values
bool

acceptsHtml()

Determines whether a request accepts HTML.

public acceptsHtml() : bool
Return values
bool

acceptsJson()

Determines whether a request accepts JSON.

public acceptsJson() : bool
Return values
bool

ajax()

Determine if the request is the result of an AJAX call.

public ajax() : bool
Return values
bool

all()

Get all of the input and files for the request.

public all([array<string|int, mixed>|mixed $keys = null ]) : array<string|int, mixed>
Parameters
$keys : array<string|int, mixed>|mixed = null
Return values
array<string|int, mixed>

allFiles()

Get an array of all of the files on the request.

public allFiles() : array<string|int, mixed>
Return values
array<string|int, mixed>

attributes()

Get custom attributes for validator errors.

public attributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

bearerToken()

Get the bearer token from the request headers.

public bearerToken() : string|null
Return values
string|null

capture()

Create a new Illuminate HTTP request from server variables.

public static capture() : static
Return values
static

Retrieve a cookie from the request.

public cookie([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

create()

Creates a Request based on a given URI and configuration.

public static create(string $uri[, string $method = 'GET' ][, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string|resource|null $content = null ]) : static

The information contained in the URI always take precedence over the other information (server and parameters).

Parameters
$uri : string

The URI

$method : string = 'GET'

The HTTP method

$parameters : array<string|int, mixed> = []

The query (GET) or request (POST) parameters

$cookies : array<string|int, mixed> = []

The request cookies ($_COOKIE)

$files : array<string|int, mixed> = []

The request files ($_FILES)

$server : array<string|int, mixed> = []

The server parameters ($_SERVER)

$content : string|resource|null = null

The raw body data

Return values
static

createFromBase()

Create an Illuminate request from a Symfony instance.

public static createFromBase(Request $request) : Request
Parameters
$request : Request
Return values
Request

createFromGlobals()

Creates a new request with values from PHP's super globals.

public static createFromGlobals() : static
Return values
static

decodedPath()

Get the current decoded path info for the request.

public decodedPath() : string
Return values
string

duplicate()

Clones a request and overrides some of its parameters.

public duplicate([array<string|int, mixed> $query = null ][, array<string|int, mixed> $request = null ][, array<string|int, mixed> $attributes = null ][, array<string|int, mixed> $cookies = null ][, array<string|int, mixed> $files = null ][, array<string|int, mixed> $server = null ]) : static
Parameters
$query : array<string|int, mixed> = null

The GET parameters

$request : array<string|int, mixed> = null

The POST parameters

$attributes : array<string|int, mixed> = null

The request attributes (parameters parsed from the PATH_INFO, ...)

$cookies : array<string|int, mixed> = null

The COOKIE parameters

$files : array<string|int, mixed> = null

The FILES parameters

$server : array<string|int, mixed> = null

The SERVER parameters

Return values
static

enableHttpMethodParameterOverride()

Enables support for the _method request parameter to determine the intended HTTP method.

public static enableHttpMethodParameterOverride() : mixed

Be warned that enabling this feature might lead to CSRF issues in your code. Check that you are using CSRF tokens when required. If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered and used to send a "PUT" or "DELETE" request via the _method request parameter. If these methods are not protected against CSRF, this presents a possible vulnerability.

The HTTP method can only be overridden when the real HTTP method is POST.

Return values
mixed

except()

Get all of the input except for a specified array of items.

public except(array<string|int, mixed>|mixed $keys) : array<string|int, mixed>
Parameters
$keys : array<string|int, mixed>|mixed
Return values
array<string|int, mixed>

exists()

Determine if the request contains a given input item key.

public exists(string|array<string|int, mixed> $key) : bool
Parameters
$key : string|array<string|int, mixed>
Return values
bool

expectsJson()

Determine if the current request probably expects a JSON response.

public expectsJson() : bool
Return values
bool

file()

Retrieve a file from the request.

public file([string $key = null ][, mixed $default = null ]) : UploadedFile|array<string|int, mixed>|null
Parameters
$key : string = null
$default : mixed = null
Return values
UploadedFile|array<string|int, mixed>|null

filled()

Determine if the request contains a non-empty value for an input item.

public filled(string|array<string|int, mixed> $key) : bool
Parameters
$key : string|array<string|int, mixed>
Return values
bool

fingerprint()

Get a unique fingerprint for the request / route / IP address.

public fingerprint() : string
Tags
throws
RuntimeException
Return values
string

flash()

Flash the input for the current request to the session.

public flash() : void
Return values
void

flashExcept()

Flash only some of the input to the session.

public flashExcept(array<string|int, mixed>|mixed $keys) : void
Parameters
$keys : array<string|int, mixed>|mixed
Return values
void

flashOnly()

Flash only some of the input to the session.

public flashOnly(array<string|int, mixed>|mixed $keys) : void
Parameters
$keys : array<string|int, mixed>|mixed
Return values
void

flush()

Flush all of the old input from the session.

public flush() : void
Return values
void

format()

Get the data format expected in the response.

public format([string $default = 'html' ]) : string
Parameters
$default : string = 'html'
Return values
string

fullUrl()

Get the full URL for the request.

public fullUrl() : string
Return values
string

fullUrlIs()

Determine if the current request URL and query string matches a pattern.

public fullUrlIs(dynamic ...$patterns) : bool
Parameters
$patterns : dynamic
Return values
bool

fullUrlWithQuery()

Get the full URL for the request with the added query string parameters.

public fullUrlWithQuery(array<string|int, mixed> $query) : string
Parameters
$query : array<string|int, mixed>
Return values
string

get()

Gets a "parameter" value from any bag.

public get(string $key[, mixed $default = null ]) : mixed

This method is mainly useful for libraries that want to provide some flexibility. If you don't need the flexibility in controllers, it is better to explicitly get request parameters from the appropriate public property instead (attributes, query, request).

Order of precedence: PATH (routing placeholders or custom attributes), GET, BODY

Parameters
$key : string

The key

$default : mixed = null

The default value if the parameter key does not exist

Return values
mixed

getAcceptableContentTypes()

Gets a list of content types acceptable by the client browser.

public getAcceptableContentTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of content types in preferable order

getBasePath()

Returns the root path from which this request is executed.

public getBasePath() : string

Suppose that an index.php file instantiates this request object:

  • http://localhost/index.php returns an empty string
  • http://localhost/index.php/page returns an empty string
  • http://localhost/web/index.php returns '/web'
  • http://localhost/we%20b/index.php returns '/we%20b'
Return values
string

The raw path (i.e. not urldecoded)

getBaseUrl()

Returns the root URL from which this request is executed.

public getBaseUrl() : string

The base URL never ends with a /.

This is similar to getBasePath(), except that it also includes the script filename (e.g. index.php) if one exists.

Return values
string

The raw URL (i.e. not urldecoded)

getCharsets()

Gets a list of charsets acceptable by the client browser.

public getCharsets() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of charsets in preferable order

getClientIp()

Returns the client IP address.

public getClientIp() : string|null

This method can read the client IP address from the "X-Forwarded-For" header when trusted proxies were set via "setTrustedProxies()". The "X-Forwarded-For" header value is a comma+space separated list of IP addresses, the left-most being the original client, and each successive proxy that passed the request adding the IP address where it received the request from.

If your reverse proxy uses a different header name than "X-Forwarded-For", ("Client-Ip" for instance), configure it via the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.

Tags
see
getClientIps()
see
https://wikipedia.org/wiki/X-Forwarded-For
Return values
string|null

The client IP address

getClientIps()

Returns the client IP addresses.

public getClientIps() : array<string|int, mixed>

In the returned array the most trusted IP address is first, and the least trusted one last. The "real" client IP address is the last one, but this is also the least trusted one. Trusted proxies are stripped.

Use this method carefully; you should use getClientIp() instead.

Tags
see
getClientIp()
Return values
array<string|int, mixed>

The client IP addresses

getContent()

Returns the request body content.

public getContent([bool $asResource = false ]) : string|resource
Parameters
$asResource : bool = false

If true, a resource will be returned

Tags
throws
LogicException
Return values
string|resource

The request body content or a resource to read the body stream

getContentType()

Gets the format associated with the request.

public getContentType() : string|null
Return values
string|null

The format (null if no content type is present)

getDefaultLocale()

Get the default locale.

public getDefaultLocale() : string
Return values
string

getEncodings()

Gets a list of encodings acceptable by the client browser.

public getEncodings() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of encodings in preferable order

getETags()

Gets the Etags.

public getETags() : array<string|int, mixed>
Return values
array<string|int, mixed>

The entity tags

getFormat()

Gets the format associated with the mime type.

public getFormat(string $mimeType) : string|null
Parameters
$mimeType : string

The associated mime type

Return values
string|null

The format (null if not found)

getHost()

Returns the host name.

public getHost() : string

This method can read the client host name from the "X-Forwarded-Host" header when trusted proxies were set via "setTrustedProxies()".

The "X-Forwarded-Host" header must contain the client host name.

If your reverse proxy uses a different header name than "X-Forwarded-Host", configure it via the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.

Tags
throws
SuspiciousOperationException

when the host name is invalid or not trusted

Return values
string

getHttpHost()

Returns the HTTP host being requested.

public getHttpHost() : string

The port name will be appended to the host if it's non-standard.

Return values
string

getHttpMethodParameterOverride()

Checks whether support for the _method request parameter is enabled.

public static getHttpMethodParameterOverride() : bool
Return values
bool

True when the _method request parameter is enabled, false otherwise

getLanguages()

Gets a list of languages acceptable by the client browser.

public getLanguages() : array<string|int, mixed>
Return values
array<string|int, mixed>

Languages ordered in the user browser preferences

getLocale()

Get the locale.

public getLocale() : string
Return values
string

getMethod()

Gets the request "intended" method.

public getMethod() : string

If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the "real" intended HTTP method.

The _method request parameter can also be used to determine the HTTP method, but only if enableHttpMethodParameterOverride() has been called.

The method is always an uppercased string.

Tags
see
getRealMethod()
Return values
string

The request method

getMimeType()

Gets the mime type associated with the format.

public getMimeType(string $format) : string|null
Parameters
$format : string

The format

Return values
string|null

The associated mime type (null if not found)

getMimeTypes()

Gets the mime types associated with the format.

public static getMimeTypes(string $format) : array<string|int, mixed>
Parameters
$format : string

The format

Return values
array<string|int, mixed>

The associated mime types

getPassword()

Returns the password.

public getPassword() : string|null
Return values
string|null

getPathInfo()

Returns the path being requested relative to the executed script.

public getPathInfo() : string

The path info always starts with a /.

Suppose this request is instantiated from /mysite on localhost:

  • http://localhost/mysite returns an empty string
  • http://localhost/mysite/about returns '/about'
  • http://localhost/mysite/enco%20ded returns '/enco%20ded'
  • http://localhost/mysite/about?var=1 returns '/about'
Return values
string

The raw path (i.e. not urldecoded)

getPort()

Returns the port on which the request is made.

public getPort() : int|string

This method can read the client port from the "X-Forwarded-Port" header when trusted proxies were set via "setTrustedProxies()".

The "X-Forwarded-Port" header must contain the client port.

If your reverse proxy uses a different header name than "X-Forwarded-Port", configure it via via the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.

Return values
int|string

can be a string if fetched from the server bag

getPreferredLanguage()

Returns the preferred language.

public getPreferredLanguage([array<string|int, mixed> $locales = null ]) : string|null
Parameters
$locales : array<string|int, mixed> = null

An array of ordered available locales

Return values
string|null

The preferred locale

getProtocolVersion()

Returns the protocol version.

public getProtocolVersion() : string

If the application is behind a proxy, the protocol version used in the requests between the client and the proxy and between the proxy and the server might be different. This returns the former (from the "Via" header) if the proxy is trusted (see "setTrustedProxies()"), otherwise it returns the latter (from the "SERVER_PROTOCOL" server parameter).

Return values
string

getQueryString()

Generates the normalized query string for the Request.

public getQueryString() : string|null

It builds a normalized query string, where keys/value pairs are alphabetized and have consistent escaping.

Return values
string|null

A normalized query string for the Request

getRealMethod()

Gets the "real" request method.

public getRealMethod() : string
Tags
see
getMethod()
Return values
string

The request method

getRelativeUriForPath()

Returns the path as relative reference from the current Request path.

public getRelativeUriForPath(string $path) : string

Only the URIs path component (no schema, host etc.) is relevant and must be given. Both paths must be absolute and not contain relative parts. Relative URLs from one resource to another are useful when generating self-contained downloadable document archives. Furthermore, they can be used to reduce the link size in documents.

Example target paths, given a base path of "/a/b/c/d":

  • "/a/b/c/d" -> ""
  • "/a/b/c/" -> "./"
  • "/a/b/" -> "../"
  • "/a/b/c/other" -> "other"
  • "/a/x/y" -> "../../x/y"
Parameters
$path : string

The target path

Return values
string

The relative target path

getRequestFormat()

Gets the request format.

public getRequestFormat([string|null $default = 'html' ]) : string|null

Here is the process to determine the format:

  • format defined by the user (with setRequestFormat())
  • _format request attribute
  • $default
Parameters
$default : string|null = 'html'

The default format

Return values
string|null

The request format

getRequestUri()

Returns the requested URI (path and query string).

public getRequestUri() : string
Return values
string

The raw URI (i.e. not URI decoded)

getRouteResolver()

Get the route resolver callback.

public getRouteResolver() : Closure
Return values
Closure

getScheme()

Gets the request's scheme.

public getScheme() : string
Return values
string

getSchemeAndHttpHost()

Gets the scheme and HTTP host.

public getSchemeAndHttpHost() : string

If the URL was called with basic authentication, the user and the password are not added to the generated string.

Return values
string

The scheme and HTTP host

getScriptName()

Returns current script name.

public getScriptName() : string
Return values
string

getTrustedHeaderName()

Gets the trusted proxy header name.

public static getTrustedHeaderName(string $key) : string
Parameters
$key : string

The header key

Tags
throws
InvalidArgumentException
deprecated

since version 3.3, to be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.

Return values
string

The header name

getTrustedHeaderSet()

Gets the set of trusted headers from trusted proxies.

public static getTrustedHeaderSet() : int
Return values
int

A bit field of Request::HEADER_* that defines which headers are trusted from your proxies

getTrustedHosts()

Gets the list of trusted host patterns.

public static getTrustedHosts() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of trusted host patterns

getTrustedProxies()

Gets the list of trusted proxies.

public static getTrustedProxies() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of trusted proxies

getUri()

Generates a normalized URI (URL) for the Request.

public getUri() : string
Tags
see
getQueryString()
Return values
string

A normalized URI (URL) for the Request

getUriForPath()

Generates a normalized URI for the given path.

public getUriForPath(string $path) : string
Parameters
$path : string

A path to use instead of the current one

Return values
string

The normalized URI for the path

getUser()

Returns the user.

public getUser() : string|null
Return values
string|null

getUserInfo()

Gets the user info.

public getUserInfo() : string
Return values
string

A user name and, optionally, scheme-specific information about how to gain authorization to access the server

getUserResolver()

Get the user resolver callback.

public getUserResolver() : Closure
Return values
Closure

has()

Determine if the request contains a given input item key.

public has(string|array<string|int, mixed> $key) : bool
Parameters
$key : string|array<string|int, mixed>
Return values
bool

hasAny()

Determine if the request contains any of the given inputs.

public hasAny(mixed ...$keys) : bool
Parameters
$keys : mixed
Return values
bool

hasCookie()

Determine if a cookie is set on the request.

public hasCookie(string $key) : bool
Parameters
$key : string
Return values
bool

hasFile()

Determine if the uploaded data contains a file.

public hasFile(string $key) : bool
Parameters
$key : string
Return values
bool

hasHeader()

Determine if a header is set on the request.

public hasHeader(string $key) : bool
Parameters
$key : string
Return values
bool

hasMacro()

Checks if macro is registered.

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

hasPreviousSession()

Whether the request contains a Session which was started in one of the previous requests.

public hasPreviousSession() : bool
Return values
bool

hasSession()

Whether the request contains a Session object.

public hasSession() : bool

This method does not give any information about the state of the session object, like whether the session is started or not. It is just a way to check if this Request is associated with a Session instance.

Return values
bool

true when the Request contains a Session object, false otherwise

header()

Retrieve a header from the request.

public header([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

initialize()

Sets the parameters for this request.

public initialize([array<string|int, mixed> $query = [] ][, array<string|int, mixed> $request = [] ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string|resource|null $content = null ]) : mixed

This method also re-initializes all properties.

Parameters
$query : array<string|int, mixed> = []

The GET parameters

$request : array<string|int, mixed> = []

The POST parameters

$attributes : array<string|int, mixed> = []

The request attributes (parameters parsed from the PATH_INFO, ...)

$cookies : array<string|int, mixed> = []

The COOKIE parameters

$files : array<string|int, mixed> = []

The FILES parameters

$server : array<string|int, mixed> = []

The SERVER parameters

$content : string|resource|null = null

The raw body data

Return values
mixed

input()

Retrieve an input item from the request.

public input([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

instance()

Return the Request instance.

public instance() : $this
Return values
$this

ip()

Get the client IP address.

public ip() : string
Return values
string

ips()

Get the client IP addresses.

public ips() : array<string|int, mixed>
Return values
array<string|int, mixed>

is()

Determine if the current request URI matches a pattern.

public is(dynamic ...$patterns) : bool
Parameters
$patterns : dynamic
Return values
bool

isFromTrustedProxy()

Indicates whether this request originated from a trusted proxy.

public isFromTrustedProxy() : bool

This can be useful to determine whether or not to trust the contents of a proxy-specific header.

Return values
bool

true if the request came from a trusted proxy, false otherwise

isMethod()

Checks if the request method is of specified type.

public isMethod(string $method) : bool
Parameters
$method : string

Uppercase request method (GET, POST etc)

Return values
bool

isMethodIdempotent()

Checks whether or not the method is idempotent.

public isMethodIdempotent() : bool
Return values
bool

isNoCache()

public isNoCache() : bool
Return values
bool

isSecure()

Checks whether the request is secure or not.

public isSecure() : bool

This method can read the client protocol from the "X-Forwarded-Proto" header when trusted proxies were set via "setTrustedProxies()".

The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".

If your reverse proxy uses a different header name than "X-Forwarded-Proto" ("SSL_HTTPS" for instance), configure it via the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.

Return values
bool

isXmlHttpRequest()

Returns true if the request is a XMLHttpRequest.

public isXmlHttpRequest() : bool

It works if your JavaScript library sets an X-Requested-With HTTP header. It is known to work with common JavaScript frameworks:

Tags
see
https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
Return values
bool

true if the request is an XMLHttpRequest, false otherwise

json()

Get the JSON payload for the request.

public json([string $key = null ][, mixed $default = null ]) : ParameterBag|mixed
Parameters
$key : string = null
$default : mixed = null
Return values
ParameterBag|mixed

keys()

Get the keys for all of the input and files.

public keys() : array<string|int, mixed>
Return values
array<string|int, mixed>

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Return values
void

matchesType()

Determine if the given content types match.

public static matchesType(string $actual, string $type) : bool
Parameters
$actual : string
$type : string
Return values
bool

merge()

Merge new input into the current request's input array.

public merge(array<string|int, mixed> $input) : Request
Parameters
$input : array<string|int, mixed>
Return values
Request

messages()

Get custom messages for validator errors.

public messages() : array<string|int, mixed>
Return values
array<string|int, mixed>

method()

Get the request method.

public method() : string
Return values
string

mixin()

Mix another object into the class.

public static mixin(object $mixin) : void
Parameters
$mixin : object
Return values
void

normalizeQueryString()

Normalizes a query string.

public static normalizeQueryString(string $qs) : string

It builds a normalized query string, where keys/value pairs are alphabetized, have consistent escaping and unneeded delimiters are removed.

Parameters
$qs : string

Query string

Return values
string

A normalized query string for the Request

offsetExists()

Determine if the given offset exists.

public offsetExists(string $offset) : bool
Parameters
$offset : string
Return values
bool

offsetGet()

Get the value at the given offset.

public offsetGet(string $offset) : mixed
Parameters
$offset : string
Return values
mixed

offsetSet()

Set the value at the given offset.

public offsetSet(string $offset, mixed $value) : void
Parameters
$offset : string
$value : mixed
Return values
void

offsetUnset()

Remove the value at the given offset.

public offsetUnset(string $offset) : void
Parameters
$offset : string
Return values
void

old()

Retrieve an old input item.

public old([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

only()

Get a subset containing the provided keys with values from the input data.

public only(array<string|int, mixed>|mixed $keys) : array<string|int, mixed>
Parameters
$keys : array<string|int, mixed>|mixed
Return values
array<string|int, mixed>

overrideGlobals()

Overrides the PHP global variables according to this request instance.

public overrideGlobals() : mixed

It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. $_FILES is never overridden, see rfc1867

Return values
mixed

path()

Get the current path info for the request.

public path() : string
Return values
string

pjax()

Determine if the request is the result of an PJAX call.

public pjax() : bool
Return values
bool

post()

Retrieve a request payload item from the request.

public post([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

prefers()

Return the most suitable content type from the given array based on content negotiation.

public prefers(string|array<string|int, mixed> $contentTypes) : string|null
Parameters
$contentTypes : string|array<string|int, mixed>
Return values
string|null

query()

Retrieve a query string item from the request.

public query([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

replace()

Replace the input for the current request.

public replace(array<string|int, mixed> $input) : Request
Parameters
$input : array<string|int, mixed>
Return values
Request

root()

Get the root URL for the application.

public root() : string
Return values
string

route()

Get the route handling the request.

public route([string|null $param = null ]) : Route|object|string
Parameters
$param : string|null = null
Return values
Route|object|string

routeIs()

Determine if the route name matches a given pattern.

public routeIs(dynamic ...$patterns) : bool
Parameters
$patterns : dynamic
Return values
bool

secure()

Determine if the request is over HTTPS.

public secure() : bool
Return values
bool

segment()

Get a segment from the URI (1 based index).

public segment(int $index[, string|null $default = null ]) : string|null
Parameters
$index : int
$default : string|null = null
Return values
string|null

segments()

Get all of the segments for the request path.

public segments() : array<string|int, mixed>
Return values
array<string|int, mixed>

server()

Retrieve a server variable from the request.

public server([string $key = null ][, string|array<string|int, mixed>|null $default = null ]) : string|array<string|int, mixed>
Parameters
$key : string = null
$default : string|array<string|int, mixed>|null = null
Return values
string|array<string|int, mixed>

session()

Get the session associated with the request.

public session() : Store
Tags
throws
RuntimeException
Return values
Store

setContainer()

Set the container implementation.

public setContainer(Container $container) : $this
Parameters
$container : Container
Return values
$this

setDefaultLocale()

Sets the default locale.

public setDefaultLocale(string $locale) : mixed
Parameters
$locale : string
Return values
mixed

setFactory()

Sets a callable able to create a Request instance.

public static setFactory(callable|null $callable) : mixed

This is mainly useful when you need to override the Request class to keep BC with an existing system. It should not be used for any other purpose.

Parameters
$callable : callable|null

A PHP callable

Return values
mixed

setFormat()

Associates a format with mime types.

public setFormat(string $format, string|array<string|int, mixed> $mimeTypes) : mixed
Parameters
$format : string

The format

$mimeTypes : string|array<string|int, mixed>

The associated mime types (the preferred one must be the first as it will be used as the content type)

Return values
mixed

setLaravelSession()

Set the session instance on the request.

public setLaravelSession(Session $session) : void
Parameters
$session : Session
Return values
void

setLocale()

Sets the locale.

public setLocale(string $locale) : mixed
Parameters
$locale : string
Return values
mixed

setMethod()

Sets the request method.

public setMethod(string $method) : mixed
Parameters
$method : string
Return values
mixed

setRedirector()

Set the Redirector instance.

public setRedirector(Redirector $redirector) : $this
Parameters
$redirector : Redirector
Return values
$this

setRequestFormat()

Sets the request format.

public setRequestFormat(string $format) : mixed
Parameters
$format : string

The request format

Return values
mixed

setRouteResolver()

Set the route resolver callback.

public setRouteResolver(Closure $callback) : $this
Parameters
$callback : Closure
Return values
$this

setTrustedHeaderName()

Sets the name for trusted headers.

public static setTrustedHeaderName(string $key, string $value) : mixed

The following header keys are supported:

  • Request::HEADER_CLIENT_IP: defaults to X-Forwarded-For (see getClientIp())
  • Request::HEADER_CLIENT_HOST: defaults to X-Forwarded-Host (see getHost())
  • Request::HEADER_CLIENT_PORT: defaults to X-Forwarded-Port (see getPort())
  • Request::HEADER_CLIENT_PROTO: defaults to X-Forwarded-Proto (see getScheme() and isSecure())
  • Request::HEADER_FORWARDED: defaults to Forwarded (see RFC 7239)

Setting an empty value allows to disable the trusted header for the given key.

Parameters
$key : string

The header key

$value : string

The header name

Tags
throws
InvalidArgumentException
deprecated

since version 3.3, to be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.

Return values
mixed

setTrustedHosts()

Sets a list of trusted host patterns.

public static setTrustedHosts(array<string|int, mixed> $hostPatterns) : mixed

You should only list the hosts you manage using regexs.

Parameters
$hostPatterns : array<string|int, mixed>

A list of trusted host patterns

Return values
mixed

setTrustedProxies()

Sets a list of trusted proxies.

public static setTrustedProxies(array<string|int, mixed> $proxies) : mixed

You should only list the reverse proxies that you manage directly.

Parameters
$proxies : array<string|int, mixed>

A list of trusted proxies

Tags
throws
InvalidArgumentException

When $trustedHeaderSet is invalid

Return values
mixed

setUserResolver()

Set the user resolver callback.

public setUserResolver(Closure $callback) : $this
Parameters
$callback : Closure
Return values
$this

toArray()

Get all of the input and files for the request.

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

url()

Get the URL (no query string) for the request.

public url() : string
Return values
string

user()

Get the user making the request.

public user([string|null $guard = null ]) : mixed
Parameters
$guard : string|null = null
Return values
mixed

userAgent()

Get the client user agent.

public userAgent() : string
Return values
string

validated()

Get the validated data from the request.

public validated() : array<string|int, mixed>
Return values
array<string|int, mixed>

wantsJson()

Determine if the current request is asking for JSON in return.

public wantsJson() : bool
Return values
bool

convertUploadedFiles()

Convert the given array of Symfony UploadedFiles to custom Laravel UploadedFiles.

protected convertUploadedFiles(array<string|int, mixed> $files) : array<string|int, mixed>
Parameters
$files : array<string|int, mixed>
Return values
array<string|int, mixed>

filterFiles()

Filter the given array of files, removing any empty values.

protected filterFiles(mixed $files) : mixed
Parameters
$files : mixed
Return values
mixed

getRedirectUrl()

Get the URL to redirect to on a validation error.

protected getRedirectUrl() : string
Return values
string

initializeFormats()

Initializes HTTP request formats.

protected static initializeFormats() : mixed
Return values
mixed

isEmptyString()

Determine if the given input key is an empty string for "has".

protected isEmptyString(string $key) : bool
Parameters
$key : string
Return values
bool

isValidFile()

Check that the given file is a valid file instance.

protected isValidFile(mixed $file) : bool
Parameters
$file : mixed
Return values
bool

passesAuthorization()

Determine if the request passes the authorization check.

protected passesAuthorization() : bool
Return values
bool

prepareBasePath()

Prepares the base path.

protected prepareBasePath() : string
Return values
string

base path

prepareBaseUrl()

Prepares the base URL.

protected prepareBaseUrl() : string
Return values
string

prepareForValidation()

Prepare the data for validation.

protected prepareForValidation() : void
Return values
void

preparePathInfo()

Prepares the path info.

protected preparePathInfo() : string
Return values
string

path info

prepareRequestUri()

protected prepareRequestUri() : mixed
Return values
mixed

retrieveItem()

Retrieve a parameter item from a given source.

protected retrieveItem(string $source, string $key, string|array<string|int, mixed>|null $default) : string|array<string|int, mixed>
Parameters
$source : string
$key : string
$default : string|array<string|int, mixed>|null
Return values
string|array<string|int, mixed>

validationData()

Get data to be validated from the request.

protected validationData() : array<string|int, mixed>
Return values
array<string|int, mixed>

createRequestFromFactory()

private static createRequestFromFactory([array<string|int, mixed> $query = [] ][, array<string|int, mixed> $request = [] ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, mixed $content = null ]) : mixed
Parameters
$query : array<string|int, mixed> = []
$request : array<string|int, mixed> = []
$attributes : array<string|int, mixed> = []
$cookies : array<string|int, mixed> = []
$files : array<string|int, mixed> = []
$server : array<string|int, mixed> = []
$content : mixed = null
Return values
mixed

getTrustedValues()

private getTrustedValues(mixed $type[, mixed $ip = null ]) : mixed
Parameters
$type : mixed
$ip : mixed = null
Return values
mixed

getUrlencodedPrefix()

Returns the prefix as encoded in the string when the string starts with the given prefix, false otherwise.

private getUrlencodedPrefix(string $string, string $prefix) : string|false
Parameters
$string : string

The urlencoded string

$prefix : string

The prefix not encoded

Return values
string|false

The prefix as it is encoded in $string, or false

normalizeAndFilterClientIps()

private normalizeAndFilterClientIps(array<string|int, mixed> $clientIps, mixed $ip) : mixed
Parameters
$clientIps : array<string|int, mixed>
$ip : mixed
Return values
mixed

setPhpDefaultLocale()

Sets the default PHP locale.

private setPhpDefaultLocale(string $locale) : mixed
Parameters
$locale : string
Return values
mixed

Search results