Router
class Router implements BindingRegistrar, Registrar (View source)
Traits
Macroable |
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|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. | |
static array | $verbs | All of the verbs supported by the router. |
Methods
static void | macro(string $name, object|callable $macro) Register a custom macro. | from Macroable |
static void | mixin(object $mixin, bool $replace = true) Mix another object into the class. | from Macroable |
static bool | hasMacro(string $name) Checks if macro is registered. | from Macroable |
static mixed | __callStatic(string $method, array $parameters) Dynamically handle calls to the class. | from Macroable |
mixed | __call(string $method, array $parameters) Dynamically handle calls into the router instance. | |
void | __construct(Dispatcher $events, Container $container = null) Create a new Router instance. | |
Route | get(string $uri, Closure|array|string|callable $action = null) Register a new GET route with the router. | |
Route | post(string $uri, Closure|array|string|callable $action = null) Register a new POST route with the router. | |
Route | put(string $uri, Closure|array|string|callable $action = null) Register a new PUT route with the router. | |
Route | patch(string $uri, Closure|array|string|callable $action = null) Register a new PATCH route with the router. | |
Route | delete(string $uri, Closure|array|string|callable $action = null) Register a new DELETE route with the router. | |
Route | options(string $uri, Closure|array|string|callable $action = null) Register a new OPTIONS route with the router. | |
Route | any(string $uri, Closure|array|string|callable|null $action = null) Register a new route responding to all verbs. | |
Route | fallback(Closure|array|string|callable|null $action) Register a new Fallback route with the router. | |
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 = []) Register a new route that returns a view. | |
Route | match(array|string $methods, string $uri, Closure|array|string|callable $action = null) Register a new route with the given verbs. | |
void | resources(array $resources, array $options = []) Register an array of resource controllers. | |
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 | group(array $attributes, Closure|string $routes) Create a route group with shared attributes. | |
void | updateGroupStack(array $attributes) Update the group stack with the given attributes. | |
array | mergeWithLastGroup(array $new) Merge the given array with the last group stack. | |
void | loadRoutes(Closure|string $routes) Load the provided routes. | |
string | getLastGroupPrefix() Get the prefix from the last group on the stack. | |
Route | addRoute(array|string $methods, string $uri, Closure|array|string|callable|null $action) Add a route to the underlying route collection. | |
Route | createRoute(array|string $methods, string $uri, mixed $action) Create a new route instance. | |
bool | actionReferencesController(array $action) Determine if the action is routing to a controller. | |
array | convertToControllerAction(array|string $action) Add a controller based route action to the action array. | |
string | prependGroupNamespace(string $class) Prepend the last group namespace onto the use clause. | |
Route | newRoute(array|string $methods, string $uri, mixed $action) Create a new Route object. | |
string | prefix(string $uri) Prefix the given URI with the last prefix. | |
Route | addWhereClausesToRoute(Route $route) Add the necessary where clauses to the route based on its initial registration. | |
void | mergeGroupAttributesIntoRoute(Route $route) Merge the group stack with the controller action. | |
Response | respondWithRoute(string $name) Return the response returned by the given route. | |
Response | dispatch(Request $request) Dispatch the request to the application. | |
Response | dispatchToRoute(Request $request) Dispatch the request to a route and return the response. | |
Route | findRoute(Request $request) Find the route matching a given request. | |
Response | runRoute(Request $request, Route $route) Return the response for the given route. | |
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 | sortMiddleware(Collection $middlewares) Sort the given middleware by priority. | |
Response | prepareResponse(Request $request, mixed $response) Create a response instance from the given value. | |
static Response | toResponse(Request $request, mixed $response) Static version of prepareResponse. | |
Route | substituteBindings(Route $route) Substitute the route bindings onto the route. | |
void | substituteImplicitBindings(Route $route) Substitute the implicit Eloquent model bindings for the route. | |
mixed | performBinding(string $key, string $value, Route $route) Call the binding callback for the given key. | |
void | matched(string|callable $callback) Register a route matched event listener. | |
array | getMiddleware() Get all of the defined middleware short-hand names. | |
$this | aliasMiddleware(string $name, string $class) Register a short-hand name for a middleware. | |
bool | hasMiddlewareGroup(string $name) Check if a middlewareGroup with the given name exists. | |
array | getMiddlewareGroups() Get all of the defined middleware groups. | |
$this | middlewareGroup(string $name, array $middleware) Register a group of middleware. | |
$this | prependMiddlewareToGroup(string $group, string $middleware) Add a middleware to the beginning of a middleware group. | |
$this | pushMiddlewareToGroup(string $group, string $middleware) Add a middleware to the end of a middleware group. | |
void | bind(string $key, string|callable $binder) Add a new route parameter binder. | |
void | model(string $key, string $class, Closure $callback = null) Register a model binder for a wildcard. | |
Closure | getBindingCallback(string $key) Get the binding callback for a given binding. | |
array | getPatterns() Get the global "where" patterns. | |
void | pattern(string $key, string $pattern) Set a global where pattern on all routes. | |
void | patterns(array $patterns) Set a group of global where patterns on all routes. | |
bool | hasGroupStack() Determine if the router currently has a group stack. | |
array | getGroupStack() Get the current group stack for the router. | |
mixed | input(string $key, string|null $default = null) Get a route parameter for the current route. | |
Request | getCurrentRequest() Get the request currently being dispatched. | |
Route | getCurrentRoute() Get the currently dispatched route instance. | |
Route|null | current() Get the currently dispatched route instance. | |
bool | has(string $name) Check if a route with the given name exists. | |
string|null | currentRouteName() Get the current route name. | |
bool | is(mixed ...$patterns) Alias for the "currentRouteNamed" method. | |
bool | currentRouteNamed(mixed ...$patterns) Determine if the current route matches a pattern. | |
string|null | currentRouteAction() Get the current route action. | |
bool | uses(array ...$patterns) Alias for the "currentRouteUses" method. | |
bool | currentRouteUses(string $action) Determine if the current route action matches a given action. | |
void | auth(array $options = []) Register the typical authentication routes for an application. | |
void | resetPassword() Register the typical reset password routes for an application. | |
void | confirmPassword() Register the typical confirm password routes for an application. | |
void | emailVerification() Register the typical email verification routes for an application. | |
void | singularResourceParameters(bool $singular = true) Set the unmapped global resource parameters to singular. | |
void | resourceParameters(array $parameters = []) Set the global resource parameter mapping. | |
array|null | resourceVerbs(array $verbs = []) Get or set the verbs used in the resource URIs. | |
RouteCollection | getRoutes() Get the underlying route collection. | |
void | setRoutes(RouteCollection $routes) Set the route collection instance. | |
static array | uniqueMiddleware(array $middleware) Remove any duplicate middleware from the given array. |
Details
static void macro(string $name, object|callable $macro)
Register a custom macro.
static void mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool hasMacro(string $name)
Checks if macro is registered.
static mixed __callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed __call(string $method, array $parameters)
Dynamically handle calls into the router instance.
void __construct(Dispatcher $events, Container $container = null)
Create a new Router instance.
Route get(string $uri, Closure|array|string|callable $action = null)
Register a new GET route with the router.
Route post(string $uri, Closure|array|string|callable $action = null)
Register a new POST route with the router.
Route put(string $uri, Closure|array|string|callable $action = null)
Register a new PUT route with the router.
Route patch(string $uri, Closure|array|string|callable $action = null)
Register a new PATCH route with the router.
Route delete(string $uri, Closure|array|string|callable $action = null)
Register a new DELETE route with the router.
Route options(string $uri, Closure|array|string|callable $action = null)
Register a new OPTIONS route with the router.
Route any(string $uri, Closure|array|string|callable|null $action = null)
Register a new route responding to all verbs.
Route fallback(Closure|array|string|callable|null $action)
Register a new Fallback route with the router.
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 = [])
Register a new route that returns a view.
Route match(array|string $methods, string $uri, Closure|array|string|callable $action = null)
Register a new route with the given verbs.
void resources(array $resources, array $options = [])
Register an array of resource controllers.
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 group(array $attributes, Closure|string $routes)
Create a route group with shared attributes.
protected void updateGroupStack(array $attributes)
Update the group stack with the given attributes.
array mergeWithLastGroup(array $new)
Merge the given array with the last group stack.
protected void loadRoutes(Closure|string $routes)
Load the provided routes.
string getLastGroupPrefix()
Get the prefix from the last group on the stack.
Route addRoute(array|string $methods, string $uri, Closure|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(array $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 Route newRoute(array|string $methods, string $uri, mixed $action)
Create a new Route object.
protected string prefix(string $uri)
Prefix the given URI with the last prefix.
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.
Response respondWithRoute(string $name)
Return the response returned by the given route.
Response dispatch(Request $request)
Dispatch the request to the application.
Response dispatchToRoute(Request $request)
Dispatch the request to a route and return the response.
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.
protected array sortMiddleware(Collection $middlewares)
Sort the given middleware by priority.
Response prepareResponse(Request $request, mixed $response)
Create a response instance from the given value.
static Response toResponse(Request $request, mixed $response)
Static version of prepareResponse.
void substituteImplicitBindings(Route $route)
Substitute the implicit Eloquent model bindings for the route.
protected mixed performBinding(string $key, string $value, Route $route)
Call the binding callback for the given key.
void matched(string|callable $callback)
Register a route matched event listener.
array getMiddleware()
Get all of the defined middleware short-hand names.
$this aliasMiddleware(string $name, string $class)
Register a short-hand name for a middleware.
bool hasMiddlewareGroup(string $name)
Check if a middlewareGroup with the given name exists.
array getMiddlewareGroups()
Get all of the defined middleware groups.
$this middlewareGroup(string $name, array $middleware)
Register a group of middleware.
$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.
void bind(string $key, string|callable $binder)
Add a new route parameter binder.
void model(string $key, string $class, Closure $callback = null)
Register a model binder for a wildcard.
Closure getBindingCallback(string $key)
Get the binding callback for a given binding.
array getPatterns()
Get the global "where" patterns.
void pattern(string $key, string $pattern)
Set a global where pattern on all routes.
void patterns(array $patterns)
Set a group of global where patterns on all routes.
bool hasGroupStack()
Determine if the router currently has a group stack.
array getGroupStack()
Get the current group stack for the router.
mixed input(string $key, string|null $default = null)
Get a route parameter for the current route.
Request getCurrentRequest()
Get the request currently being dispatched.
Route getCurrentRoute()
Get the currently dispatched route instance.
Route|null current()
Get the currently dispatched route instance.
bool has(string $name)
Check if a route with the given name exists.
string|null currentRouteName()
Get the current route name.
bool is(mixed ...$patterns)
Alias for the "currentRouteNamed" method.
bool currentRouteNamed(mixed ...$patterns)
Determine if the current route matches a pattern.
string|null currentRouteAction()
Get the current route action.
bool uses(array ...$patterns)
Alias for the "currentRouteUses" method.
bool currentRouteUses(string $action)
Determine if the current route action matches a given action.
void auth(array $options = [])
Register the typical authentication routes for an application.
void resetPassword()
Register the typical reset password routes for an application.
void confirmPassword()
Register the typical confirm password routes for an application.
void emailVerification()
Register the typical email verification routes for an application.
void singularResourceParameters(bool $singular = true)
Set the unmapped global resource parameters to singular.
void resourceParameters(array $parameters = [])
Set the global resource parameter mapping.
array|null resourceVerbs(array $verbs = [])
Get or set the verbs used in the resource URIs.
RouteCollection getRoutes()
Get the underlying route collection.
void setRoutes(RouteCollection $routes)
Set the route collection instance.
static array uniqueMiddleware(array $middleware)
Remove any duplicate middleware from the given array.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/6.x/Illuminate/Routing/Router.html