class Middleware

Properties

protected array|null $global

The user defined global middleware stack.

protected array $prepends

The middleware that should be prepended to the global middleware stack.

protected array $appends

The middleware that should be appended to the global middleware stack.

protected array $removals

The middleware that should be removed from the global middleware stack.

protected array $replacements

The middleware that should be replaced in the global middleware stack.

protected array $groups

The user defined middleware groups.

protected array $groupPrepends

The middleware that should be prepended to the specified groups.

protected array $groupAppends

The middleware that should be appended to the specified groups.

protected array $groupRemovals

The middleware that should be removed from the specified groups.

protected array $groupReplacements

The middleware that should be replaced in the specified groups.

protected bool $trustHosts

Indicates if the "trust hosts" middleware is enabled.

protected bool $statefulApi

Indicates if Sanctum's frontend state middleware is enabled.

protected string|null $apiLimiter

Indicates the API middleware group's rate limiter.

protected bool $authenticatedSessions

Indicates if sessions should be authenticated for the "web" middleware group.

protected array $customAliases

The custom middleware aliases.

protected array $priority

The custom middleware priority definition.

protected array $prependPriority

The middleware to prepend to the middleware priority definition.

protected array $appendPriority

The middleware to append to the middleware priority definition.

Methods

prepend(array|string $middleware)

Prepend middleware to the application's global middleware stack.

append(array|string $middleware)

Append middleware to the application's global middleware stack.

remove(array|string $middleware)

Remove middleware from the application's global middleware stack.

replace(string $search, array|string $replace)

Specify a middleware that should be replaced with another middleware.

insertBefore(string $search, array|string $middleware)

Insert middleware before the given middleware in the global middleware stack.

insertAfter(string $search, array|string $middleware)

Insert middleware after the given middleware in the global middleware stack.

use(array $middleware)

Define the global middleware for the application.

group(string $group, array $middleware)

Define a middleware group.

prependToGroup(string $group, array|string $middleware)

Prepend the given middleware to the specified group.

appendToGroup(string $group, array|string $middleware)

Append the given middleware to the specified group.

removeFromGroup(string $group, array|string $middleware)

Remove the given middleware from the specified group.

replaceInGroup(string $group, string $search, array|string $replace)

Replace the given middleware in the specified group with another middleware.

insertBeforeInGroup(string $group, string $search, array|string $middleware)

Insert middleware before the given middleware in the specified group.

insertAfterInGroup(string $group, string $search, array|string $middleware)

Insert middleware after the given middleware in the specified group.

web(array|string $append = [], array|string $prepend = [], array|string $remove = [], array $replace = [])

Modify the middleware in the "web" group.

api(array|string $append = [], array|string $prepend = [], array|string $remove = [], array $replace = [])

Modify the middleware in the "api" group.

modifyGroup(string $group, array|string $append, array|string $prepend, array|string $remove, array $replace)

Modify the middleware in the given group.

alias(array $aliases)

Register additional middleware aliases.

priority(array $priority)

Define the middleware priority for the application.

prependToPriorityList(array|string $before, string $prepend)

Prepend middleware to the priority middleware.

appendToPriorityList(array|string $after, string $append)

Append middleware to the priority middleware.

array
getGlobalMiddleware()

Get the global middleware.

array
getMiddlewareGroups()

Get the middleware groups.

redirectGuestsTo(callable|string|null $redirect)

Configure where guests are redirected by the "auth" middleware.

redirectUsersTo(callable|string $redirect)

Configure where users are redirected by the "guest" middleware.

redirectTo(callable|string|null $guests = null, callable|string|null $users = null)

Configure where users are redirected by the authentication and guest middleware.

encryptCookies(array $except = [], array $only = [])

Configure the cookie encryption middleware.

preventRequestForgery(array $except = [], bool $originOnly = false, bool $allowSameSite = false)

Configure the request forgery prevention middleware.

validateSignatures(array $except = [])

Configure the URL signature validation middleware.

convertEmptyStringsToNull(array $except = [])

Configure the empty string conversion middleware.

trimStrings(array $except = [])

Configure the string trimming middleware.

trustHosts(array|callable|null $at = null, bool $subdomains = true)

Indicate that the trusted host middleware should be enabled.

trustProxies(array|string|null $at = null, int|null $headers = null)

Configure the trusted proxies for the application.

preventRequestsDuringMaintenance(array $except = [])

Configure the middleware that prevents requests during maintenance mode.

statefulApi()

Indicate that Sanctum's frontend state middleware should be enabled.

throttleApi(string $limiter = 'api')

Indicate that the API middleware group's throttling middleware should be enabled.

authenticateSessions()

Indicate that sessions should be authenticated for the "web" middleware group.

array
getMiddlewareAliases()

Get the middleware aliases.

array
defaultAliases()

Get the default middleware aliases.

array
getMiddlewarePriority()

Get the middleware priority for the application.

array
getMiddlewarePriorityPrepends()

Get the middleware to prepend to the middleware priority definition.

array
getMiddlewarePriorityAppends()

Get the middleware to append to the middleware priority definition.

Details

at line 120
Middleware prepend(array|string $middleware)

Prepend middleware to the application's global middleware stack.

Parameters

array|string $middleware

Return Value

Middleware

at line 135
Middleware append(array|string $middleware)

Append middleware to the application's global middleware stack.

Parameters

array|string $middleware

Return Value

Middleware

at line 150
Middleware remove(array|string $middleware)

Remove middleware from the application's global middleware stack.

Parameters

array|string $middleware

Return Value

Middleware

at line 165
Middleware replace(string $search, array|string $replace)

Specify a middleware that should be replaced with another middleware.

Parameters

string $search
array|string $replace

Return Value

Middleware

at line 177
Middleware insertBefore(string $search, array|string $middleware)

Insert middleware before the given middleware in the global middleware stack.

Parameters

string $search
array|string $middleware

Return Value

Middleware

at line 190
Middleware insertAfter(string $search, array|string $middleware)

Insert middleware after the given middleware in the global middleware stack.

Parameters

string $search
array|string $middleware

Return Value

Middleware

at line 203
Middleware use(array $middleware)

Define the global middleware for the application.

Parameters

array $middleware

Return Value

Middleware

at line 215
Middleware group(string $group, array $middleware)

Define a middleware group.

Parameters

string $group
array $middleware

Return Value

Middleware

at line 227
Middleware prependToGroup(string $group, array|string $middleware)

Prepend the given middleware to the specified group.

Parameters

string $group
array|string $middleware

Return Value

Middleware

at line 242
Middleware appendToGroup(string $group, array|string $middleware)

Append the given middleware to the specified group.

Parameters

string $group
array|string $middleware

Return Value

Middleware

at line 257
Middleware removeFromGroup(string $group, array|string $middleware)

Remove the given middleware from the specified group.

Parameters

string $group
array|string $middleware

Return Value

Middleware

at line 272
Middleware replaceInGroup(string $group, string $search, array|string $replace)

Replace the given middleware in the specified group with another middleware.

Parameters

string $group
string $search
array|string $replace

Return Value

Middleware

at line 284
Middleware insertBeforeInGroup(string $group, string $search, array|string $middleware)

Insert middleware before the given middleware in the specified group.

Parameters

string $group
string $search
array|string $middleware

Return Value

Middleware

at line 297
Middleware insertAfterInGroup(string $group, string $search, array|string $middleware)

Insert middleware after the given middleware in the specified group.

Parameters

string $group
string $search
array|string $middleware

Return Value

Middleware

at line 310
Middleware web(array|string $append = [], array|string $prepend = [], array|string $remove = [], array $replace = [])

Modify the middleware in the "web" group.

Parameters

array|string $append
array|string $prepend
array|string $remove
array $replace

Return Value

Middleware

at line 320
Middleware api(array|string $append = [], array|string $prepend = [], array|string $remove = [], array $replace = [])

Modify the middleware in the "api" group.

Parameters

array|string $append
array|string $prepend
array|string $remove
array $replace

Return Value

Middleware

at line 330
protected Middleware modifyGroup(string $group, array|string $append, array|string $prepend, array|string $remove, array $replace)

Modify the middleware in the given group.

Parameters

string $group
array|string $append
array|string $prepend
array|string $remove
array $replace

Return Value

Middleware

at line 360
Middleware alias(array $aliases)

Register additional middleware aliases.

Parameters

array $aliases

Return Value

Middleware

at line 372
Middleware priority(array $priority)

Define the middleware priority for the application.

Parameters

array $priority

Return Value

Middleware

at line 384
Middleware prependToPriorityList(array|string $before, string $prepend)

Prepend middleware to the priority middleware.

Parameters

array|string $before
string $prepend

Return Value

Middleware

at line 396
Middleware appendToPriorityList(array|string $after, string $append)

Append middleware to the priority middleware.

Parameters

array|string $after
string $append

Return Value

Middleware

at line 406
array getGlobalMiddleware()

Get the global middleware.

Return Value

array

at line 435
array getMiddlewareGroups()

Get the middleware groups.

Return Value

array

at line 493
Middleware redirectGuestsTo(callable|string|null $redirect)

Configure where guests are redirected by the "auth" middleware.

The callback persists in authentication middleware and exception static properties for the worker lifetime and affects every subsequent unauthenticated or session-mismatch request.

Parameters

callable|string|null $redirect

Return Value

Middleware

at line 510
Middleware redirectUsersTo(callable|string $redirect)

Configure where users are redirected by the "guest" middleware.

The callback persists in the guest middleware static property for the worker lifetime and affects every subsequent already-authenticated guest-route request.

Parameters

callable|string $redirect

Return Value

Middleware

at line 525
Middleware redirectTo(callable|string|null $guests = null, callable|string|null $users = null)

Configure where users are redirected by the authentication and guest middleware.

The callbacks persist in authentication middleware and exception static properties for the worker lifetime and affect every subsequent matching request.

Parameters

callable|string|null $guests
callable|string|null $users

Return Value

Middleware

at line 543
Middleware encryptCookies(array $except = [], array $only = [])

Configure the cookie encryption middleware.

The cookie lists persist in static properties for the worker lifetime and apply to every subsequent request.

Parameters

array $except
array $only

Return Value

Middleware

at line 565
Middleware preventRequestForgery(array $except = [], bool $originOnly = false, bool $allowSameSite = false)

Configure the request forgery prevention middleware.

The settings persist in static properties for the worker lifetime and apply to every subsequent request.

Parameters

array $except
bool $originOnly
bool $allowSameSite

Return Value

Middleware

at line 590
Middleware validateSignatures(array $except = [])

Configure the URL signature validation middleware.

The parameter list persists in a static property for the worker lifetime and applies to every subsequent request.

Parameters

array $except

Return Value

Middleware

at line 607
Middleware convertEmptyStringsToNull(array $except = [])

Configure the empty string conversion middleware.

Skip callbacks persist in a static property for the worker lifetime and run on every subsequent request.

Parameters

array $except

Return Value

Middleware

at line 624
Middleware trimStrings(array $except = [])

Configure the string trimming middleware.

The exceptions persist in static properties for the worker lifetime and apply to every subsequent request.

Parameters

array $except

Return Value

Middleware

at line 645
Middleware trustHosts(array|callable|null $at = null, bool $subdomains = true)

Indicate that the trusted host middleware should be enabled.

Given hosts persist in static properties for the worker lifetime and apply to every subsequent request.

Parameters

array|callable|null $at
bool $subdomains

Return Value

Middleware

at line 666
Middleware trustProxies(array|string|null $at = null, int|null $headers = null)

Configure the trusted proxies for the application.

Given proxies and headers persist in static properties for the worker lifetime and apply to every subsequent request.

Parameters

array|string|null $at
int|null $headers

Return Value

Middleware

at line 689
Middleware preventRequestsDuringMaintenance(array $except = [])

Configure the middleware that prevents requests during maintenance mode.

The URI list persists in a static property for the worker lifetime and applies to every subsequent request.

Parameters

array $except

Return Value

Middleware

at line 702
Middleware statefulApi()

Indicate that Sanctum's frontend state middleware should be enabled.

Return Value

Middleware

at line 714
Middleware throttleApi(string $limiter = 'api')

Indicate that the API middleware group's throttling middleware should be enabled.

Parameters

string $limiter

Return Value

Middleware

at line 729
Middleware authenticateSessions()

Indicate that sessions should be authenticated for the "web" middleware group.

Return Value

Middleware

at line 739
array getMiddlewareAliases()

Get the middleware aliases.

Return Value

array

at line 747
protected array defaultAliases()

Get the default middleware aliases.

Return Value

array

at line 768
array getMiddlewarePriority()

Get the middleware priority for the application.

Return Value

array

at line 776
array getMiddlewarePriorityPrepends()

Get the middleware to prepend to the middleware priority definition.

Return Value

array

at line 784
array getMiddlewarePriorityAppends()

Get the middleware to append to the middleware priority definition.

Return Value

array