Router
class Router implements BindingRegistrar, Registrar mixin RouteRegistrar (View source)
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 RouteCollectionInterface | $routes | The route collection instance. |
|
protected Route|null | $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. |
|
protected array | $implicitBindingCallback | The registered custom implicit binding callback. |
|
static string[] | $verbs | All of the verbs supported by the router. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls into the router instance.
Call the given Closure with this instance then return the instance.
Register a new GET route with the router.
Register a new POST route with the router.
Register a new PUT route with the router.
Register a new PATCH route with the router.
Register a new DELETE route with the router.
Register a new OPTIONS route with the router.
Register a new route responding to all verbs.
Create a redirect from one URI to another.
Create a permanent redirect from one URI to another.
Register a new route that returns a view.
Register a new route with the given verbs.
Register an array of resource controllers.
Route a resource to a controller.
Register an array of API resource controllers.
Route an API resource to a controller.
Register an array of singleton resource controllers.
Route a singleton resource to a controller.
Register an array of API singleton resource controllers.
Route an API singleton 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.
Add a route to the underlying route collection.
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.
Prepend the last group controller 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.
Return the response returned by the given route.
Run the given route within a Stack "onion" instance.
Gather the middleware for the given route with resolved class names.
Resolve a flat array of middleware classes from the provided array.
Create a response instance from the given value.
Static version of prepareResponse.
Substitute the implicit route bindings for the given route.
Register a callback to run after implicit bindings are substituted.
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.
Remove the given middleware from the specified group.
Flush the router's middleware groups.
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 pattern.
Get the current route action.
Alias for the "currentRouteUses" method.
Determine if the current route action matches a given action.
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.
Set the compiled route collection instance.
Remove any duplicate middleware from the given array.
Details
Route
get(string $uri, array|string|callable $action = null)
Register a new GET route with the router.
Route
post(string $uri, array|string|callable $action = null)
Register a new POST route with the router.
Route
put(string $uri, array|string|callable $action = null)
Register a new PUT route with the router.
Route
patch(string $uri, array|string|callable $action = null)
Register a new PATCH route with the router.
Route
delete(string $uri, array|string|callable $action = null)
Register a new DELETE route with the router.
Route
options(string $uri, array|string|callable $action = null)
Register a new OPTIONS route with the router.
Route
any(string $uri, array|string|callable|null $action = null)
Register a new route responding to all verbs.
Route
redirect(string $uri, string $destination, int $status = 302)
Create a redirect from one URI to another.
Route
permanentRedirect(string $uri, string $destination)
Create a permanent redirect from one URI to another.
Route
view(string $uri, string $view, array $data = [], int|array $status = 200, array $headers = [])
Register a new route that returns a view.
Route
match(array|string $methods, string $uri, array|string|callable $action = null)
Register a new route with the given verbs.
PendingResourceRegistration
resource(string $name, string $controller, array $options = [])
Route a resource to a controller.
void
apiResources(array $resources, array $options = [])
Register an array of API resource controllers.
PendingResourceRegistration
apiResource(string $name, string $controller, array $options = [])
Route an API resource to a controller.
void
singletons(array $singletons, array $options = [])
Register an array of singleton resource controllers.
PendingSingletonResourceRegistration
singleton(string $name, string $controller, array $options = [])
Route a singleton resource to a controller.
void
apiSingletons(array $singletons, array $options = [])
Register an array of API singleton resource controllers.
PendingSingletonResourceRegistration
apiSingleton(string $name, string $controller, array $options = [])
Route an API singleton resource to a controller.
protected void
updateGroupStack(array $attributes)
Update the group stack with the given attributes.
array
mergeWithLastGroup(array $new, bool $prependExistingPrefix = true)
Merge the given array with the last group stack.
Route
addRoute(array|string $methods, string $uri, array|string|callable|null $action)
Add a route to the underlying route collection.
protected Route
createRoute(array|string $methods, string $uri, mixed $action)
Create a new route instance.
protected bool
actionReferencesController(mixed $action)
Determine if the action is routing to a controller.
protected array
convertToControllerAction(array|string $action)
Add a controller based route action to the action array.
protected string
prependGroupNamespace(string $class)
Prepend the last group namespace onto the use clause.
protected string
prependGroupController(string $class)
Prepend the last group controller onto the use clause.
protected Route
addWhereClausesToRoute(Route $route)
Add the necessary where clauses to the route based on its initial registration.
protected void
mergeGroupAttributesIntoRoute(Route $route)
Merge the group stack with the controller action.
protected Response
runRoute(Request $request, Route $route)
Return the response for the given route.
protected mixed
runRouteWithinStack(Route $route, Request $request)
Run the given route within a Stack "onion" instance.
array
gatherRouteMiddleware(Route $route)
Gather the middleware for the given route with resolved class names.
array
resolveMiddleware(array $middleware, array $excluded = [])
Resolve a flat array of middleware classes from the provided array.
Response
prepareResponse(Request $request, mixed $response)
Create a response instance from the given value.
void
substituteImplicitBindings(Route $route)
Substitute the implicit route bindings for the given route.
$this
substituteImplicitBindingsUsing(callable $callback)
Register a callback to run after implicit bindings are substituted.
protected mixed
performBinding(string $key, string $value, Route $route)
Call the binding callback for the given key.
$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.
$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.
$this
removeMiddlewareFromGroup(string $group, string $middleware)
Remove the given middleware from the specified group.
void
model(string $key, string $class, Closure|null $callback = null)
Register a model binder for a wildcard.
void
singularResourceParameters(bool $singular = true)
Set the unmapped global resource parameters to singular.
static array
uniqueMiddleware(array $middleware)
Remove any duplicate middleware from the given array.