Route
class Route
Traits
Constants
| private PARAMS_CONTEXT_KEY_PREFIX |
Context key for coroutine-local route parameters. Route objects are cached and shared across coroutines, so per-request mutable state (parameters, controller instances) must be stored in coroutine-local Context rather than on the Route instance. |
| private ORIGINAL_PARAMS_CONTEXT_KEY_PREFIX |
Context key for coroutine-local original route parameters. |
| private CONTROLLER_CONTEXT_KEY_PREFIX |
Context key prefix for coroutine-local controller instances. |
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| static protected array<string, bool> | $enumCache | Cached isEnum results keyed by class name. |
from ResolvesRouteDependencies |
| string | $uri | The URI pattern the route responds to. |
|
| array | $methods | The HTTP methods the route responds to. |
|
| array | $action | The route action array. |
|
| bool | $isFallback | Indicates whether the route is a fallback route. |
|
| array | $defaults | The default values for the route. |
|
| array | $wheres | The regular expression requirements. |
|
| array|null | $parameterNames | The parameter names for the route. |
|
| protected bool | $withTrashedBindings | Indicates "trashed" models can be retrieved when resolving implicit model bindings for this route. |
|
| protected int|null | $lockSeconds | Indicates the maximum number of seconds the route should acquire a session lock for. |
|
| protected int|null | $waitSeconds | Indicates the maximum number of seconds the route should wait while attempting to acquire a session lock. |
|
| array|null | $computedMiddleware | The computed gathered middleware. |
|
| array|null | $resolvedMiddleware | The cached resolved middleware with class names expanded and groups resolved. |
|
| null|array<int, mixed> | $middlewareDescriptors | The cached pipeline descriptors for resolved class-string middleware. |
|
| null|array<int, mixed> | $pipelineMiddleware | The gathered middleware list the compiled pipeline was built from. |
|
| Closure|null | $middlewarePipeline | The reusable route middleware pipeline. |
|
| CompiledRoute|null | $compiled | The compiled version of the route. |
|
| protected object|null | $callable | The resolved callable for the route. |
|
| protected Closure|null | $missing | The resolved missing model handler for the route. |
|
| protected CallableDispatcher|null | $callableDispatcher | The cached callable dispatcher instance. |
|
| protected mixed | $controller | The cached controller instance for worker-shared (singleton) controllers. |
|
| protected ControllerDispatcher|null | $controllerDispatcher | The cached controller dispatcher instance. |
|
| protected Router|null | $router | The router instance used by the route. |
|
| protected Container|null | $container | The container instance used by the route. |
|
| protected array | $bindingFields | The fields that implicit binding should use for a given parameter. |
|
| static null|ValidatorInterface> | $validators | The validators used by the routes. |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Specify that the given route parameters must be alphabetic.
Specify that the given route parameters must be alphanumeric.
Specify that the given route parameters must be numeric.
Specify that the given route parameters must be ULIDs.
Specify that the given route parameters must be UUIDs.
Specify that the given route parameters must be one of the given values.
Apply the given regular expression to the given parameters.
Determine if the given options exclude a particular method.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Resolve the object method's type-hinted dependencies.
Resolve the given method's type-hinted dependencies.
Attempt to transform the given parameter into a class instance.
Determine if an object of the given class is in a list of parameters.
Splice the given value into the parameter list.
Create a new Route instance.
Parse the route action into a standard array.
Run the route action and return the response.
Check whether the route's action is a controller.
Run the callable route action and return the response.
Get the callable dispatcher for the route.
Determine if the route action is a serialized Closure.
Run the controller route action and return the response.
Get the controller instance for the route.
Get the controller class used for the route.
Get the controller method used for the route.
Parse the controller.
Flush the cached controller state on the route.
Compile the route into a Symfony CompiledRoute instance.
Ensure the route is compiled.
Bind parameters returned by the compiled route matcher.
Determine if the route has parameters.
Determine if a given parameter exists on the route.
Get a given parameter from the route.
Get original value of a given parameter from the route.
Set a parameter to the given value.
Unset a parameter on the route if it is set.
Get the key / value list of parameters for the route.
Get the key / value list of original parameters for the route.
Get the key / value list of parameters without null values.
Get all of the parameter names for the route.
Get the parameter names for the route.
Get the parameters that are listed in the route / controller signature.
Get the binding field for the given parameter.
Get the binding fields for the route.
Set the binding fields for the route.
Get the parent parameter of the given parameter.
Allow "trashed" models to be retrieved when resolving implicit model bindings for this route.
Determine if the route allows "trashed" models to be retrieved when resolving implicit model bindings.
Set the default values for the route.
Set a regular expression requirement on the route.
Parse arguments to the where method into an array.
Set the fallback value.
Get the HTTP verbs the route responds to.
Determine if the route only responds to HTTP requests.
Determine if the route only responds to HTTPS requests.
Determine if the route only responds to HTTPS requests.
Get or set the domain for the route.
Get the domain defined for the route.
Get the port defined for the route.
Get the prefix of the route instance.
Update the "prefix" attribute on the action array.
Get the URI associated with the route.
Parse the route URI and normalize / store any implicit binding fields.
Get the name of the route instance.
Determine whether the route's name matches the given patterns.
Parse a string based action for the "uses" fluent method.
Get the action name for the route.
Get the method name of the route action.
Get the action array or one of its properties for the route.
Get the value of the action that should be taken on a missing model exception.
Get all middleware, including the ones from the controller.
Get or set the middlewares attached to the route.
Specify that the "Authorize" / "can" middleware should be applied to the route.
Get the middleware for the route's controller.
Get the statically provided controller middleware for the given class and method.
Get the attribute provided controller middleware for the given class and method.
Get the excluded middleware for the route's controller.
Get the attribute provided excluded controller middleware for the given class and method.
Specify middleware that should be removed from the given route.
Get the middleware that should be removed from the route.
Indicate that the route should enforce scoping of multiple implicit Eloquent bindings.
Indicate that the route should not enforce scoping of multiple implicit Eloquent bindings.
Determine if the route should enforce scoping of multiple implicit Eloquent bindings.
Determine if the route should prevent scoping of multiple implicit Eloquent bindings.
Specify that the route should not allow concurrent requests from the same session.
Specify that the route should allow concurrent requests from the same session.
Get the maximum number of seconds the route's session lock should be held for.
Get the maximum number of seconds to wait while attempting to acquire a session lock.
Get metadata for the route.
Set the metadata for the route, replacing any existing metadata.
Get the dispatcher for the route's controller.
Get the route validators for the instance.
Convert the route to a Symfony route.
Get the optional parameter names for the route.
Get the compiled version of the route.
Prepare the route instance for serialization.
Flush all static state.
Dynamically access route parameters.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
CreatesRegularExpressionRouteConstraints at line 16
CreatesRegularExpressionRouteConstraints
whereAlpha(array|string $parameters)
Specify that the given route parameters must be alphabetic.
in
CreatesRegularExpressionRouteConstraints at line 24
CreatesRegularExpressionRouteConstraints
whereAlphaNumeric(array|string $parameters)
Specify that the given route parameters must be alphanumeric.
in
CreatesRegularExpressionRouteConstraints at line 32
CreatesRegularExpressionRouteConstraints
whereNumber(array|string $parameters)
Specify that the given route parameters must be numeric.
in
CreatesRegularExpressionRouteConstraints at line 40
CreatesRegularExpressionRouteConstraints
whereUlid(array|string $parameters)
Specify that the given route parameters must be ULIDs.
in
CreatesRegularExpressionRouteConstraints at line 48
CreatesRegularExpressionRouteConstraints
whereUuid(array|string $parameters)
Specify that the given route parameters must be UUIDs.
in
CreatesRegularExpressionRouteConstraints at line 56
CreatesRegularExpressionRouteConstraints
whereIn(array|string $parameters, array $values)
Specify that the given route parameters must be one of the given values.
in
CreatesRegularExpressionRouteConstraints at line 69
protected CreatesRegularExpressionRouteConstraints
assignExpressionToParameters(array|string $parameters, string $expression)
Apply the given regular expression to the given parameters.
in
FiltersControllerMiddleware at line 12
static bool
methodExcludedByOptions(string $method, array $options)
Determine if the given options exclude a particular method.
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
ResolvesRouteDependencies at line 33
static void
flushEnumCache()
Flush the static enum cache.
Boot or tests only. Clears the process-wide enum lookup cache shared by every coroutine; next resolution re-resolves.
in
ResolvesRouteDependencies at line 41
protected array
resolveClassMethodDependencies(array $parameters, object $instance, string $method)
Resolve the object method's type-hinted dependencies.
in
ResolvesRouteDependencies at line 58
array
resolveMethodDependencies(array $parameters, array $reflectedParameters)
Resolve the given method's type-hinted dependencies.
in
ResolvesRouteDependencies at line 91
protected mixed
transformDependency(ReflectionParameter $parameter, array $parameters, object $skippableValue)
Attempt to transform the given parameter into a class instance.
in
ResolvesRouteDependencies at line 116
protected bool
alreadyInParameters(string $class, array $parameters)
Determine if an object of the given class is in a list of parameters.
in
ResolvesRouteDependencies at line 124
protected void
spliceIntoParameters(array $parameters, int $offset, mixed $value)
Splice the given value into the parameter list.
at line 235
__construct(array|string $methods, string $uri, callable|array|null $action)
Create a new Route instance.
at line 253
protected array
parseAction(callable|array|null $action)
Parse the route action into a standard array.
at line 261
mixed
run()
Run the route action and return the response.
at line 279
protected bool
isControllerAction()
Check whether the route's action is a controller.
at line 287
protected mixed
runCallable()
Run the callable route action and return the response.
at line 307
protected CallableDispatcher
callableDispatcher()
Get the callable dispatcher for the route.
at line 315
protected bool
isSerializedClosure()
Determine if the route action is a serialized Closure.
at line 325
protected mixed
runController()
Run the controller route action and return the response.
at line 347
mixed
getController()
Get the controller instance for the route.
For worker-shared controllers (singletons and unbound auto-singletons), the instance is cached directly on the Route property for zero-overhead access across coroutines.
For controllers with per-coroutine semantics (#[Scoped] or explicit bind()), the instance is stored in coroutine Context to preserve the container's binding contract. CoroutineContext::getOrSet memoizes within a coroutine (getController() is called twice — middleware + dispatch) while still giving each coroutine its own instance.
at line 392
string|null
getControllerClass()
Get the controller class used for the route.
at line 400
protected string
getControllerMethod()
Get the controller method used for the route.
at line 408
protected array
parseControllerCallback()
Parse the controller.
at line 423
void
flushController()
Flush the cached controller state on the route.
Boot or tests only. Clears caches on the worker-shared route and evicts its controller class from the container.
Clears both the route-level property cache (for worker-shared controllers) and the coroutine Context entry (for scoped/bound controllers), plus the container's auto-singleton cache so make() creates a fresh instance.
at line 442
bool
matches(Request $request, bool $includingMethod = true)
Determine if the route matches a given request.
at line 465
protected CompiledRoute
compileRoute()
Compile the route into a Symfony CompiledRoute instance.
The compiled result is cached on the Route instance for the worker lifetime — it's immutable after compilation and safe to share.
at line 480
void
ensureCompiled()
Ensure the route is compiled.
Called during server boot pre-warming to populate the compiled regex cache before fork, so workers inherit it via copy-on-write.
at line 508
Route
bind(Request $request)
Bind the route to a given request for execution.
Parameters are stored in coroutine Context, not on the Route instance, because Route objects are cached and shared across coroutines.
at line 524
Route
bindFromCompiledMatch(array $parameters, Request $request)
| internal |
Bind parameters returned by the compiled route matcher.
at line 561
bool
hasParameters()
Determine if the route has parameters.
at line 569
bool
hasParameter(string $name)
Determine if a given parameter exists on the route.
at line 581
mixed
parameter(string $name, mixed $default = null)
Get a given parameter from the route.
at line 589
string|null
originalParameter(string $name, string|null $default = null)
Get original value of a given parameter from the route.
at line 597
void
setParameter(string $name, mixed $value)
Set a parameter to the given value.
at line 609
void
forgetParameter(string $name)
Unset a parameter on the route if it is set.
at line 623
array
parameters()
Get the key / value list of parameters for the route.
at line 639
array
originalParameters()
Get the key / value list of original parameters for the route.
at line 653
array
parametersWithoutNulls()
Get the key / value list of parameters without null values.
at line 665
array
parameterNames()
Get all of the parameter names for the route.
at line 673
protected array
compileParameterNames()
Get the parameter names for the route.
at line 683
array
signatureParameters(array|string $conditions = [])
Get the parameters that are listed in the route / controller signature.
at line 695
string|null
bindingFieldFor(string|int $parameter)
Get the binding field for the given parameter.
at line 705
array
bindingFields()
Get the binding fields for the route.
at line 713
Route
setBindingFields(array $bindingFields)
Set the binding fields for the route.
at line 723
mixed
parentOfParameter(string $parameter)
Get the parent parameter of the given parameter.
at line 738
Route
withTrashed(bool $withTrashed = true)
Allow "trashed" models to be retrieved when resolving implicit model bindings for this route.
at line 748
bool
allowsTrashedBindings()
Determine if the route allows "trashed" models to be retrieved when resolving implicit model bindings.
at line 756
Route
defaults(string $key, mixed $value)
Set a default value for the route.
at line 766
Route
setDefaults(array $defaults)
Set the default values for the route.
at line 776
Route
where(array|string $name, string|null $expression = null)
Set a regular expression requirement on the route.
at line 788
protected array
parseWhere(array|string $name, string|null $expression)
Parse arguments to the where method into an array.
at line 796
Route
setWheres(array $wheres)
Set a list of regular expression requirements on the route.
at line 808
Route
fallback()
Mark this route as a fallback route.
at line 818
Route
setFallback(bool $isFallback)
Set the fallback value.
at line 828
array
methods()
Get the HTTP verbs the route responds to.
at line 836
bool
httpOnly()
Determine if the route only responds to HTTP requests.
at line 844
bool
httpsOnly()
Determine if the route only responds to HTTPS requests.
at line 852
bool
secure()
Determine if the route only responds to HTTPS requests.
at line 864
Route|string|null
domain(BackedEnum|string|null $domain = null)
Get or set the domain for the route.
at line 889
string|null
getDomain()
Get the domain defined for the route.
at line 899
Route|int|null
port(int|null $port = null)
Get or set the port for the route.
at line 913
int|null
getPort()
Get the port defined for the route.
at line 921
string|null
getPrefix()
Get the prefix of the route instance.
at line 929
Route
prefix(string|null $prefix)
Add a prefix to the route URI.
at line 943
protected void
updatePrefixOnAction(string $prefix)
Update the "prefix" attribute on the action array.
at line 953
string
uri()
Get the URI associated with the route.
at line 961
Route
setUri(string $uri)
Set the URI that the route responds to.
at line 971
protected string
parseUri(string $uri)
Parse the route URI and normalize / store any implicit binding fields.
at line 983
string|null
getName()
Get the name of the route instance.
at line 993
Route
name(BackedEnum|string $name)
Add or change the route name.
at line 1007
bool
named(mixed ...$patterns)
Determine whether the route's name matches the given patterns.
at line 1043
protected string
addGroupNamespaceToStringUses(string $action)
Parse a string based action for the "uses" fluent method.
at line 1057
string
getActionName()
Get the action name for the route.
at line 1065
string
getActionMethod()
Get the method name of the route action.
at line 1073
mixed
getAction(string|null $key = null)
Get the action array or one of its properties for the route.
at line 1081
Route
setAction(array $action)
Set the action array for the route.
at line 1103
Closure|null
getMissing()
Get the value of the action that should be taken on a missing model exception.
at line 1131
Route
missing(Closure $missing)
Define the callable that should be invoked on a missing model exception.
at line 1142
array
gatherMiddleware()
Get all middleware, including the ones from the controller.
at line 1161
Route|array
middleware(array|string|Stringable|null $middleware = null)
Get or set the middlewares attached to the route.
at line 1186
Route
can(UnitEnum|string $ability, array|string $models = [])
Specify that the "Authorize" / "can" middleware should be applied to the route.
at line 1198
array
controllerMiddleware()
Get the middleware for the route's controller.
at line 1227
protected array
staticallyProvidedControllerMiddleware(string $class, string $method)
Get the statically provided controller middleware for the given class and method.
at line 1251
protected array
attributeProvidedControllerMiddleware(string $class, string $method)
Get the attribute provided controller middleware for the given class and method.
at line 1296
array
excludedControllerMiddleware()
Get the excluded middleware for the route's controller.
at line 1313
protected array
attributeProvidedControllerMiddlewareExclusions(string $class, string $method)
Get the attribute provided excluded controller middleware for the given class and method.
at line 1357
Route
withoutMiddleware(array|string $middleware)
Specify middleware that should be removed from the given route.
at line 1370
array
excludedMiddleware()
Get the middleware that should be removed from the route.
at line 1381
Route
scopeBindings()
Indicate that the route should enforce scoping of multiple implicit Eloquent bindings.
at line 1391
Route
withoutScopedBindings()
Indicate that the route should not enforce scoping of multiple implicit Eloquent bindings.
at line 1401
bool
enforcesScopedBindings()
Determine if the route should enforce scoping of multiple implicit Eloquent bindings.
at line 1409
bool
preventsScopedBindings()
Determine if the route should prevent scoping of multiple implicit Eloquent bindings.
at line 1417
Route
block(int|null $lockSeconds = 10, int|null $waitSeconds = 10)
Specify that the route should not allow concurrent requests from the same session.
at line 1428
Route
withoutBlocking()
Specify that the route should allow concurrent requests from the same session.
at line 1436
int|null
locksFor()
Get the maximum number of seconds the route's session lock should be held for.
at line 1444
int|null
waitsFor()
Get the maximum number of seconds to wait while attempting to acquire a session lock.
at line 1452
Route
metadata(array $metadata)
Add metadata to the route.
at line 1467
mixed
getMetadata(string|null $key = null, mixed $default = null)
Get metadata for the route.
at line 1477
Route
setMetadata(array $metadata)
Set the metadata for the route, replacing any existing metadata.
at line 1487
ControllerDispatcher
controllerDispatcher()
Get the dispatcher for the route's controller.
at line 1503
static array
getValidators()
Get the route validators for the instance.
at line 1518
Route
toSymfonyRoute()
Convert the route to a Symfony route.
at line 1536
array
getOptionalParameterNames()
Get the optional parameter names for the route.
at line 1546
CompiledRoute|null
getCompiled()
Get the compiled version of the route.
at line 1594
void
prepareForSerialization()
Prepare the route instance for serialization.
at line 1627
static void
flushState()
Flush all static state.
at line 1637
mixed
__get(string $key)
Dynamically access route parameters.