Route
class Route
Traits
Constants
| private PARAMS_CONTEXT_KEY |
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 |
Context key for coroutine-local original route parameters. |
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. |
|
| 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.
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.
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 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 87
protected mixed
transformDependency(ReflectionParameter $parameter, array $parameters, object $skippableValue)
Attempt to transform the given parameter into a class instance.
in
ResolvesRouteDependencies at line 112
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 120
protected void
spliceIntoParameters(array $parameters, int $offset, mixed $value)
Splice the given value into the parameter list.
at line 199
__construct(array|string $methods, string $uri, callable|array|null $action)
Create a new Route instance.
at line 217
protected array
parseAction(callable|array|null $action)
Parse the route action into a standard array.
at line 225
mixed
run()
Run the route action and return the response.
at line 243
protected bool
isControllerAction()
Check whether the route's action is a controller.
at line 251
protected mixed
runCallable()
Run the callable route action and return the response.
at line 265
protected CallableDispatcher
callableDispatcher()
Get the callable dispatcher for the route.
at line 273
protected bool
isSerializedClosure()
Determine if the route action is a serialized Closure.
at line 283
protected mixed
runController()
Run the controller route action and return the response.
at line 305
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 342
string|null
getControllerClass()
Get the controller class used for the route.
at line 350
protected string
getControllerMethod()
Get the controller method used for the route.
at line 358
protected array
parseControllerCallback()
Parse the controller.
at line 370
void
flushController()
Flush the cached controller state on the route.
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 386
bool
matches(Request $request, bool $includingMethod = true)
Determine if the route matches a given request.
at line 409
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 424
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 435
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 450
bool
hasParameters()
Determine if the route has parameters.
at line 458
bool
hasParameter(string $name)
Determine if a given parameter exists on the route.
at line 470
mixed
parameter(string $name, mixed $default = null)
Get a given parameter from the route.
at line 478
string|null
originalParameter(string $name, string|null $default = null)
Get original value of a given parameter from the route.
at line 486
void
setParameter(string $name, mixed $value)
Set a parameter to the given value.
at line 498
void
forgetParameter(string $name)
Unset a parameter on the route if it is set.
at line 512
array
parameters()
Get the key / value list of parameters for the route.
at line 526
array
originalParameters()
Get the key / value list of original parameters for the route.
at line 538
array
parametersWithoutNulls()
Get the key / value list of parameters without null values.
at line 546
array
parameterNames()
Get all of the parameter names for the route.
at line 558
protected array
compileParameterNames()
Get the parameter names for the route.
at line 568
array
signatureParameters(array|string $conditions = [])
Get the parameters that are listed in the route / controller signature.
at line 580
string|null
bindingFieldFor(string|int $parameter)
Get the binding field for the given parameter.
at line 590
array
bindingFields()
Get the binding fields for the route.
at line 598
Route
setBindingFields(array $bindingFields)
Set the binding fields for the route.
at line 608
mixed
parentOfParameter(string $parameter)
Get the parent parameter of the given parameter.
at line 623
Route
withTrashed(bool $withTrashed = true)
Allow "trashed" models to be retrieved when resolving implicit model bindings for this route.
at line 633
bool
allowsTrashedBindings()
Determine if the route allows "trashed" models to be retrieved when resolving implicit model bindings.
at line 641
Route
defaults(string $key, mixed $value)
Set a default value for the route.
at line 651
Route
setDefaults(array $defaults)
Set the default values for the route.
at line 661
Route
where(array|string $name, string|null $expression = null)
Set a regular expression requirement on the route.
at line 673
protected array
parseWhere(array|string $name, string|null $expression)
Parse arguments to the where method into an array.
at line 681
Route
setWheres(array $wheres)
Set a list of regular expression requirements on the route.
at line 693
Route
fallback()
Mark this route as a fallback route.
at line 703
Route
setFallback(bool $isFallback)
Set the fallback value.
at line 713
array
methods()
Get the HTTP verbs the route responds to.
at line 721
bool
httpOnly()
Determine if the route only responds to HTTP requests.
at line 729
bool
httpsOnly()
Determine if the route only responds to HTTPS requests.
at line 737
bool
secure()
Determine if the route only responds to HTTPS requests.
at line 747
Route|string|null
domain(BackedEnum|string|null $domain = null)
Get or set the domain for the route.
at line 772
string|null
getDomain()
Get the domain defined for the route.
at line 782
Route|int|null
port(int|null $port = null)
Get or set the port for the route.
at line 796
int|null
getPort()
Get the port defined for the route.
at line 804
string|null
getPrefix()
Get the prefix of the route instance.
at line 812
Route
prefix(string|null $prefix)
Add a prefix to the route URI.
at line 826
protected void
updatePrefixOnAction(string $prefix)
Update the "prefix" attribute on the action array.
at line 836
string
uri()
Get the URI associated with the route.
at line 844
Route
setUri(string $uri)
Set the URI that the route responds to.
at line 854
protected string
parseUri(string $uri)
Parse the route URI and normalize / store any implicit binding fields.
at line 866
string|null
getName()
Get the name of the route instance.
at line 876
Route
name(BackedEnum|string $name)
Add or change the route name.
at line 890
bool
named(mixed ...$patterns)
Determine whether the route's name matches the given patterns.
at line 925
protected string
addGroupNamespaceToStringUses(string $action)
Parse a string based action for the "uses" fluent method.
at line 939
string
getActionName()
Get the action name for the route.
at line 947
string
getActionMethod()
Get the method name of the route action.
at line 955
mixed
getAction(string|null $key = null)
Get the action array or one of its properties for the route.
at line 963
Route
setAction(array $action)
Set the action array for the route.
at line 985
Closure|null
getMissing()
Get the value of the action that should be taken on a missing model exception.
at line 1007
Route
missing(Closure $missing)
Define the callable that should be invoked on a missing model exception.
at line 1018
array
gatherMiddleware()
Get all middleware, including the ones from the controller.
at line 1037
Route|array
middleware(array|string|Stringable|null $middleware = null)
Get or set the middlewares attached to the route.
at line 1062
Route
can(UnitEnum|string $ability, array|string $models = [])
Specify that the "Authorize" / "can" middleware should be applied to the route.
at line 1074
array
controllerMiddleware()
Get the middleware for the route's controller.
at line 1103
protected array
staticallyProvidedControllerMiddleware(string $class, string $method)
Get the statically provided controller middleware for the given class and method.
at line 1127
protected array
attributeProvidedControllerMiddleware(string $class, string $method)
Get the attribute provided controller middleware for the given class and method.
at line 1172
Route
withoutMiddleware(array|string $middleware)
Specify middleware that should be removed from the given route.
at line 1185
array
excludedMiddleware()
Get the middleware that should be removed from the route.
at line 1193
Route
scopeBindings()
Indicate that the route should enforce scoping of multiple implicit Eloquent bindings.
at line 1203
Route
withoutScopedBindings()
Indicate that the route should not enforce scoping of multiple implicit Eloquent bindings.
at line 1213
bool
enforcesScopedBindings()
Determine if the route should enforce scoping of multiple implicit Eloquent bindings.
at line 1221
bool
preventsScopedBindings()
Determine if the route should prevent scoping of multiple implicit Eloquent bindings.
at line 1229
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 1240
Route
withoutBlocking()
Specify that the route should allow concurrent requests from the same session.
at line 1248
int|null
locksFor()
Get the maximum number of seconds the route's session lock should be held for.
at line 1256
int|null
waitsFor()
Get the maximum number of seconds to wait while attempting to acquire a session lock.
at line 1264
ControllerDispatcher
controllerDispatcher()
Get the dispatcher for the route's controller.
at line 1280
static array
getValidators()
Get the route validators for the instance.
at line 1299
Route
toSymfonyRoute()
Convert the route to a Symfony route.
at line 1317
array
getOptionalParameterNames()
Get the optional parameter names for the route.
at line 1327
CompiledRoute|null
getCompiled()
Get the compiled version of the route.
at line 1362
void
prepareForSerialization()
Prepare the route instance for serialization.
at line 1392
static void
flushState()
Flush all static state.
at line 1402
mixed
__get(string $key)
Dynamically access route parameters.