Router
class Router implements Registrar, BindingRegistrar
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected Dispatcher | $events | The event dispatcher instance. |
|
protected Container | $container | The IoC container instance. |
|
protected RouteCollection | $routes | The route collection instance. |
|
protected Route | $current | The currently dispatched route instance. |
|
protected Request | $currentRequest | The request currently being dispatched. |
|
protected array | $middleware | All of the short-hand keys for middlewares. |
|
protected array | $middlewareGroups | All of the middleware groups. |
|
array | $middlewarePriority | The priority-sorted list of middleware. |
|
protected array | $binders | The registered route value binders. |
|
protected array | $patterns | The globally available parameter patterns. |
|
protected array | $groupStack | The route group attribute stack. |
|
static array | $verbs | All of the verbs supported by the router. |
Methods
Dynamically handle calls to the class.
Dynamically handle calls into the router instance.
Register an array of resource controllers.
Route a resource to a controller.
Route an api resource to a controller.
Update the group stack with the given attributes.
Merge the given array with the last group stack.
Get the prefix from the last group on the stack.
Create a new route instance.
Determine if the action is routing to a controller.
Add a controller based route action to the action array.
Prepend the last group namespace onto the use clause.
Prefix the given URI with the last prefix.
Add the necessary where clauses to the route based on its initial registration.
Run the given route within a Stack "onion" instance.
Gather the middleware for the given route with resolved class names.
Create a response instance from the given value.
Substitute the implicit Eloquent model bindings for the route.
Call the binding callback for the given key.
Register a route matched event listener.
Get all of the defined middleware short-hand names.
Register a short-hand name for a middleware.
Check if a middlewareGroup with the given name exists.
Get all of the defined middleware groups.
Register a group of middleware.
Add a middleware to the beginning of a middleware group.
Add a middleware to the end of a middleware group.
Add a new route parameter binder.
Get the binding callback for a given binding.
Get the global "where" patterns.
Set a global where pattern on all routes.
Set a group of global where patterns on all routes.
Determine if the router currently has a group stack.
Get the current group stack for the router.
Get a route parameter for the current route.
Get the request currently being dispatched.
Get the currently dispatched route instance.
Check if a route with the given name exists.
Get the current route name.
Alias for the "currentRouteNamed" method.
Determine if the current route matches a given name.
Get the current route action.
Alias for the "currentRouteUses" method.
Determine if the current route action matches a given action.
Register the typical authentication routes for an application.
Set the unmapped global resource parameters to singular.
Set the global resource parameter mapping.
Get or set the verbs used in the resource URIs.
Get the underlying route collection.
Details
in
Macroable at line 24
static void
macro(string $name, callable $macro)
Register a custom macro.
in
Macroable at line 35
static bool
hasMacro(string $name)
Checks if macro is registered.
in
Macroable at line 49
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 1092
mixed
__call(string $method, array $parameters)
Dynamically handle calls into the router instance.
at line 118
void
__construct(Dispatcher $events, Container $container = null)
Create a new Router instance.
at line 132
Route
get(string $uri, Closure|array|string $action = null)
Register a new GET route with the router.
at line 144
Route
post(string $uri, Closure|array|string $action = null)
Register a new POST route with the router.
at line 156
Route
put(string $uri, Closure|array|string $action = null)
Register a new PUT route with the router.
at line 168
Route
patch(string $uri, Closure|array|string $action = null)
Register a new PATCH route with the router.
at line 180
Route
delete(string $uri, Closure|array|string $action = null)
Register a new DELETE route with the router.
at line 192
Route
options(string $uri, Closure|array|string $action = null)
Register a new OPTIONS route with the router.
at line 204
Route
any(string $uri, Closure|array|string|null $action = null)
Register a new route responding to all verbs.
at line 217
Route
match(array|string $methods, string $uri, Closure|array|string $action = null)
Register a new route with the given verbs.
at line 228
void
resources(array $resources)
Register an array of resource controllers.
at line 243
void
resource(string $name, string $controller, array $options = [])
Route a resource to a controller.
at line 262
void
apiResource(string $name, string $controller, array $options = [])
Route an api resource to a controller.
at line 276
void
group(array $attributes, Closure|string $routes)
Create a route group with shared attributes.
at line 294
protected void
updateGroupStack(array $attributes)
Update the group stack with the given attributes.
at line 309
array
mergeWithLastGroup(array $new)
Merge the given array with the last group stack.
at line 320
protected void
loadRoutes(Closure|string $routes)
Load the provided routes.
at line 336
string
getLastGroupPrefix()
Get the prefix from the last group on the stack.
at line 355
protected Route
addRoute(array|string $methods, string $uri, Closure|array|string|null $action)
Add a route to the underlying route collection.
at line 368
protected Route
createRoute(array|string $methods, string $uri, mixed $action)
Create a new route instance.
at line 399
protected bool
actionReferencesController(array $action)
Determine if the action is routing to a controller.
at line 414
protected array
convertToControllerAction(array|string $action)
Add a controller based route action to the action array.
at line 441
protected string
prependGroupNamespace(string $class)
Prepend the last group namespace onto the use clause.
at line 457
protected Route
newRoute(array|string $methods, string $uri, mixed $action)
Create a new Route object.
at line 470
protected string
prefix(string $uri)
Prefix the given URI with the last prefix.
at line 481
protected Route
addWhereClausesToRoute(Route $route)
Add the necessary where clauses to the route based on its initial registration.
at line 496
protected void
mergeGroupAttributesIntoRoute(Route $route)
Merge the group stack with the controller action.
at line 520
mixed
dispatchToRoute(Request $request)
Dispatch the request to a route and return the response.
at line 560
protected mixed
runRouteWithinStack(Route $route, Request $request)
Run the given route within a Stack "onion" instance.
at line 583
array
gatherRouteMiddleware(Route $route)
Gather the middleware for the given route with resolved class names.
at line 598
protected array
sortMiddleware(Collection $middlewares)
Sort the given middleware by priority.
at line 610
Response
prepareResponse(Request $request, mixed $response)
Create a response instance from the given value.
at line 644
void
substituteImplicitBindings(Route $route)
Substitute the implicit Eloquent model bindings for the route.
at line 657
protected mixed
performBinding(string $key, string $value, Route $route)
Call the binding callback for the given key.
at line 668
void
matched(string|callable $callback)
Register a route matched event listener.
at line 678
array
getMiddleware()
Get all of the defined middleware short-hand names.
at line 690
$this
aliasMiddleware(string $name, string $class)
Register a short-hand name for a middleware.
at line 703
bool
hasMiddlewareGroup(string $name)
Check if a middlewareGroup with the given name exists.
at line 713
array
getMiddlewareGroups()
Get all of the defined middleware groups.
at line 725
$this
middlewareGroup(string $name, array $middleware)
Register a group of middleware.
at line 741
$this
prependMiddlewareToGroup(string $group, string $middleware)
Add a middleware to the beginning of a middleware group.
If the middleware is already in the group, it will not be added again.
at line 759
$this
pushMiddlewareToGroup(string $group, string $middleware)
Add a middleware to the end of a middleware group.
If the middleware is already in the group, it will not be added again.
at line 779
void
bind(string $key, string|callable $binder)
Add a new route parameter binder.
at line 796
void
model(string $key, string $class, Closure $callback = null)
Register a model binder for a wildcard.
at line 807
Closure
getBindingCallback(string $key)
Get the binding callback for a given binding.
at line 819
array
getPatterns()
Get the global "where" patterns.
at line 831
void
pattern(string $key, string $pattern)
Set a global where pattern on all routes.
at line 842
void
patterns(array $patterns)
Set a group of global where patterns on all routes.
at line 854
bool
hasGroupStack()
Determine if the router currently has a group stack.
at line 864
array
getGroupStack()
Get the current group stack for the router.
at line 876
mixed
input(string $key, string $default = null)
Get a route parameter for the current route.
at line 886
Request
getCurrentRequest()
Get the request currently being dispatched.
at line 896
Route
getCurrentRoute()
Get the currently dispatched route instance.
at line 906
Route
current()
Get the currently dispatched route instance.
at line 917
bool
has(string $name)
Check if a route with the given name exists.
at line 927
string|null
currentRouteName()
Get the current route name.
at line 937
bool
is()
Alias for the "currentRouteNamed" method.
at line 954
bool
currentRouteNamed(string $name)
Determine if the current route matches a given name.
at line 964
string|null
currentRouteAction()
Get the current route action.
at line 980
bool
uses()
Alias for the "currentRouteUses" method.
at line 997
bool
currentRouteUses(string $action)
Determine if the current route action matches a given action.
at line 1007
void
auth()
Register the typical authentication routes for an application.
at line 1031
void
singularResourceParameters(bool $singular = true)
Set the unmapped global resource parameters to singular.
at line 1042
void
resourceParameters(array $parameters = [])
Set the global resource parameter mapping.
at line 1053
array|null
resourceVerbs(array $verbs = [])
Get or set the verbs used in the resource URIs.
at line 1063
RouteCollection
getRoutes()
Get the underlying route collection.
at line 1074
void
setRoutes(RouteCollection $routes)
Set the route collection instance.