Router
class Router implements 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 | $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 | $patternFilters | The registered pattern based filters. | |
protected array | $regexFilters | The registered regular expression based filters. | |
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, callable $macro) Register a custom macro. | 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 to the class. | from Macroable |
void | __construct(Dispatcher $events, Container $container = null) Create a new Router instance. | |
void | get(string $uri, Closure|array|string $action) Register a new GET route with the router. | |
void | post(string $uri, Closure|array|string $action) Register a new POST route with the router. | |
void | put(string $uri, Closure|array|string $action) Register a new PUT route with the router. | |
void | patch(string $uri, Closure|array|string $action) Register a new PATCH route with the router. | |
void | delete(string $uri, Closure|array|string $action) Register a new DELETE route with the router. | |
void | options(string $uri, Closure|array|string $action) Register a new OPTIONS route with the router. | |
Route | any(string $uri, Closure|array|string $action) Register a new route responding to all verbs. | |
void | match(array|string $methods, string $uri, Closure|array|string $action) Register a new route with the given verbs. | |
void | controllers(array $controllers) Register an array of controllers with wildcard routing. | |
void | controller(string $uri, string $controller, array $names = []) Route a controller to a URI with wildcard routing. | |
void | registerInspected(array $route, string $controller, string $method, array $names) Register an inspected controller route. | |
void | addFallthroughRoute(string $controller, string $uri) Add a fallthrough route for a controller. | |
void | resources(array $resources) Register an array of resource controllers. | |
void | resource(string $name, string $controller, array $options = []) Route a resource to a controller. | |
void | group(array $attributes, Closure $callback) 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. | |
static array | mergeGroup(array $new, array $old) Merge the given group attributes. | |
static string|null | formatUsesPrefix(array $new, array $old) Format the uses prefix for the new group attributes. | |
static string|null | formatGroupPrefix(array $new, array $old) Format the prefix for the new group attributes. | |
string | getLastGroupPrefix() Get the prefix from the last group on the stack. | |
Route | addRoute(array|string $methods, string $uri, Closure|array|string $action) Add a route to the underlying route collection. | |
Route | createRoute(array|string $methods, string $uri, mixed $action) Create a new route instance. | |
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. | |
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 | prependGroupUses(string $uses) Prepend the last group uses onto the use clause. | |
Response | dispatch(Request $request) Dispatch the request to the application. | |
mixed | dispatchToRoute(Request $request) Dispatch the request to a route and return the response. | |
mixed | runRouteWithinStack(Route $route, Request $request) Run the given route within a Stack "onion" instance. | |
array | gatherRouteMiddlewares(Route $route) Gather the middleware for the given route. | |
string | resolveMiddlewareClassName(string $name) Resolve the middleware name to a class name preserving passed parameters. | |
Route | findRoute(Request $request) Find the route matching a given request. | |
Route | substituteBindings(Route $route) Substitute the route bindings onto 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. | |
void | before(string|callable $callback) deprecated Register a new "before" filter with the router. | |
void | after(string|callable $callback) deprecated Register a new "after" filter with the router. | |
void | addGlobalFilter(string $filter, string|callable $callback) Register a new global filter with the router. | |
array | getMiddleware() Get all of the defined middleware short-hand names. | |
$this | middleware(string $name, string $class) Register a short-hand name for a middleware. | |
void | filter(string $name, string|callable $callback) deprecated Register a new filter with the router. | |
mixed | parseFilter(callable|string $callback) Parse the registered filter. | |
void | when(string $pattern, string $name, array|null $methods = null) deprecated Register a pattern-based filter with the router. | |
void | whenRegex(string $pattern, string $name, array|null $methods = null) deprecated Register a regular expression based filter with the router. | |
void | model(string $key, string $class, Closure $callback = null) Register a model binder for a wildcard. | |
void | bind(string $key, string|callable $binder) Add a new route parameter binder. | |
Closure | createClassBinding(string $binding) Create a class based binding using the IoC container. | |
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. | |
mixed | callFilter(string $filter, Request $request, Response $response = null) Call the given filter with the request and response. | |
mixed | callRouteBefore(Route $route, Request $request) Call the given route's before filters. | |
mixed | callPatternFilters(Route $route, Request $request) Call the pattern based filters for the request. | |
array | findPatternFilters(Request $request) deprecated Find the patterned filters matching a request. | |
array | patternsByMethod(string $method, array $filters) Filter pattern filters that don't apply to the request verb. | |
bool | filterSupportsMethod(array $filter, array $method) Determine if the given pattern filters applies to a given method. | |
mixed | callAttachedBefores(Route $route, Request $request) Call the given route's before (non-pattern) filters. | |
mixed | callRouteAfter(Route $route, Request $request, Response $response) deprecated Call the given route's after filters. | |
mixed | callRouteFilter(string $filter, array $parameters, Route $route, Request $request, Response|null $response = null) deprecated Call the given route filter. | |
array | cleanFilterParameters(array $parameters) Clean the parameters being passed to a filter callback. | |
Response | prepareResponse(Request $request, mixed $response) Create a response instance from the given value. | |
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 $default = null) Get a route parameter for the current route. | |
Route | getCurrentRoute() Get the currently dispatched route instance. | |
Route | 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() Alias for the "currentRouteNamed" method. | |
bool | currentRouteNamed(string $name) Determine if the current route matches a given name. | |
string|null | currentRouteAction() Get the current route action. | |
bool | uses() Alias for the "currentRouteUses" method. | |
bool | currentRouteUses(string $action) Determine if the current route action matches a given action. | |
Request | getCurrentRequest() Get the request currently being dispatched. | |
RouteCollection | getRoutes() Get the underlying route collection. | |
void | setRoutes(RouteCollection $routes) Set the route collection instance. | |
array | getPatterns() Get the global "where" patterns. |
Details
static void macro(string $name, callable $macro)
Register a custom macro.
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 to the class.
void __construct(Dispatcher $events, Container $container = null)
Create a new Router instance.
void get(string $uri, Closure|array|string $action)
Register a new GET route with the router.
void post(string $uri, Closure|array|string $action)
Register a new POST route with the router.
void put(string $uri, Closure|array|string $action)
Register a new PUT route with the router.
void patch(string $uri, Closure|array|string $action)
Register a new PATCH route with the router.
void delete(string $uri, Closure|array|string $action)
Register a new DELETE route with the router.
void options(string $uri, Closure|array|string $action)
Register a new OPTIONS route with the router.
void match(array|string $methods, string $uri, Closure|array|string $action)
Register a new route with the given verbs.
void controllers(array $controllers)
Register an array of controllers with wildcard routing.
void controller(string $uri, string $controller, array $names = [])
Route a controller to a URI with wildcard routing.
protected void registerInspected(array $route, string $controller, string $method, array $names)
Register an inspected controller route.
protected void addFallthroughRoute(string $controller, string $uri)
Add a fallthrough route for a controller.
void resources(array $resources)
Register an array of resource controllers.
void resource(string $name, string $controller, array $options = [])
Route a resource to a controller.
void group(array $attributes, Closure $callback)
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.
static array mergeGroup(array $new, array $old)
Merge the given group attributes.
static protected string|null formatUsesPrefix(array $new, array $old)
Format the uses prefix for the new group attributes.
static protected string|null formatGroupPrefix(array $new, array $old)
Format the prefix for the new group attributes.
string getLastGroupPrefix()
Get the prefix from the last group on the stack.
protected Route addRoute(array|string $methods, string $uri, Closure|array|string $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 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.
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 prependGroupUses(string $uses)
Prepend the last group uses onto the use clause.
mixed dispatchToRoute(Request $request)
Dispatch the request to a route and return the response.
protected mixed runRouteWithinStack(Route $route, Request $request)
Run the given route within a Stack "onion" instance.
array gatherRouteMiddlewares(Route $route)
Gather the middleware for the given route.
string resolveMiddlewareClassName(string $name)
Resolve the middleware name to a class name preserving passed parameters.
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.
void before(string|callable $callback) deprecated
deprecated
Register a new "before" filter with the router.
void after(string|callable $callback) deprecated
deprecated
Register a new "after" filter with the router.
protected void addGlobalFilter(string $filter, string|callable $callback)
Register a new global filter with the router.
array getMiddleware()
Get all of the defined middleware short-hand names.
$this middleware(string $name, string $class)
Register a short-hand name for a middleware.
void filter(string $name, string|callable $callback) deprecated
deprecated
Register a new filter with the router.
protected mixed parseFilter(callable|string $callback)
Parse the registered filter.
void when(string $pattern, string $name, array|null $methods = null) deprecated
deprecated
Register a pattern-based filter with the router.
void whenRegex(string $pattern, string $name, array|null $methods = null) deprecated
deprecated
Register a regular expression based filter with the router.
void model(string $key, string $class, Closure $callback = null)
Register a model binder for a wildcard.
void bind(string $key, string|callable $binder)
Add a new route parameter binder.
Closure createClassBinding(string $binding)
Create a class based binding using the IoC container.
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.
protected mixed callFilter(string $filter, Request $request, Response $response = null)
Call the given filter with the request and response.
protected mixed callPatternFilters(Route $route, Request $request)
Call the pattern based filters for the request.
array findPatternFilters(Request $request) deprecated
deprecated
Find the patterned filters matching a request.
protected array patternsByMethod(string $method, array $filters)
Filter pattern filters that don't apply to the request verb.
protected bool filterSupportsMethod(array $filter, array $method)
Determine if the given pattern filters applies to a given method.
protected mixed callAttachedBefores(Route $route, Request $request)
Call the given route's before (non-pattern) filters.
mixed callRouteAfter(Route $route, Request $request, Response $response) deprecated
deprecated
Call the given route's after filters.
mixed callRouteFilter(string $filter, array $parameters, Route $route, Request $request, Response|null $response = null) deprecated
deprecated
Call the given route filter.
protected array cleanFilterParameters(array $parameters)
Clean the parameters being passed to a filter callback.
Response prepareResponse(Request $request, mixed $response)
Create a response instance from the given value.
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 $default = null)
Get a route parameter for the current route.
Route getCurrentRoute()
Get the currently dispatched route instance.
Route 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()
Alias for the "currentRouteNamed" method.
bool currentRouteNamed(string $name)
Determine if the current route matches a given name.
string|null currentRouteAction()
Get the current route action.
bool uses()
Alias for the "currentRouteUses" method.
bool currentRouteUses(string $action)
Determine if the current route action matches a given action.
Request getCurrentRequest()
Get the request currently being dispatched.
RouteCollection getRoutes()
Get the underlying route collection.
void setRoutes(RouteCollection $routes)
Set the route collection instance.
array getPatterns()
Get the global "where" patterns.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.1/Illuminate/Routing/Router.html