class Router implements Registrar, BindingRegistrar (View source)

Traits

Properties

array $middlewarePriority The priority-sorted list of middleware.
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 into the router instance.

void
__construct(Dispatcher $events, Container $container = null)

Create a new Router instance.

get(string $uri, Closure|array|string $action = null)

Register a new GET route with the router.

post(string $uri, Closure|array|string $action = null)

Register a new POST route with the router.

put(string $uri, Closure|array|string $action = null)

Register a new PUT route with the router.

patch(string $uri, Closure|array|string $action = null)

Register a new PATCH route with the router.

delete(string $uri, Closure|array|string $action = null)

Register a new DELETE route with the router.

options(string $uri, Closure|array|string $action = null)

Register a new OPTIONS route with the router.

any(string $uri, Closure|array|string|null $action = null)

Register a new route responding to all verbs.

match(array|string $methods, string $uri, Closure|array|string $action = null)

Register a new route with the given verbs.

void
resources(array $resources)

Register an array of resource controllers.

void
resource(string $name, string $controller, array $options = array())

Route a resource to a controller.

void
apiResource(string $name, string $controller, array $options = array())

Route an api resource to a controller.

void
group(array $attributes, Closure|string $routes)

Create a route group with shared attributes.

array
mergeWithLastGroup(array $new)

Merge the given array with the last group stack.

string
getLastGroupPrefix()

Get the prefix from the last group on the stack.

dispatch(Request $request)

Dispatch the request to the application.

mixed
dispatchToRoute(Request $request)

Dispatch the request to a route and return the response.

array
gatherRouteMiddleware(Route $route)

Gather the middleware for the given route with resolved class names.

prepareResponse(Request $request, mixed $response)

Create a response instance from the given value.

substituteBindings(Route $route)

Substitute the route bindings onto the route.

void
substituteImplicitBindings(Route $route)

Substitute the implicit Eloquent model bindings for the route.

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.

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 $default = null)

Get a route parameter for the current route.

getCurrentRequest()

Get the request currently being dispatched.

getCurrentRoute()

Get the currently dispatched route instance.

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.

void
auth()

Register the typical authentication routes for an application.

void
singularResourceParameters(bool $singular = true)

Set the unmapped global resource parameters to singular.

void
resourceParameters(array $parameters = array())

Set the global resource parameter mapping.

array|null
resourceVerbs(array $verbs = array())

Get or set the verbs used in the resource URIs.

getRoutes()

Get the underlying route collection.

void
setRoutes(RouteCollection $routes)

Set the route collection instance.

Details

in Macroable at line line 24
static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

in Macroable at line line 35
static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line line 49
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line line 1094
mixed __call(string $method, array $parameters)

Dynamically handle calls into the router instance.

Parameters

string $method
array $parameters

Return Value

mixed

at line line 118
void __construct(Dispatcher $events, Container $container = null)

Create a new Router instance.

Parameters

Dispatcher $events
Container $container

Return Value

void

at line line 132
Route get(string $uri, Closure|array|string $action = null)

Register a new GET route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

at line line 144
Route post(string $uri, Closure|array|string $action = null)

Register a new POST route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

at line line 156
Route put(string $uri, Closure|array|string $action = null)

Register a new PUT route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

at line line 168
Route patch(string $uri, Closure|array|string $action = null)

Register a new PATCH route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

at line line 180
Route delete(string $uri, Closure|array|string $action = null)

Register a new DELETE route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

at line line 192
Route options(string $uri, Closure|array|string $action = null)

Register a new OPTIONS route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

at line line 204
Route any(string $uri, Closure|array|string|null $action = null)

Register a new route responding to all verbs.

Parameters

string $uri
Closure|array|string|null $action

Return Value

Route

at line line 219
Route match(array|string $methods, string $uri, Closure|array|string $action = null)

Register a new route with the given verbs.

Parameters

array|string $methods
string $uri
Closure|array|string $action

Return Value

Route

at line line 230
void resources(array $resources)

Register an array of resource controllers.

Parameters

array $resources

Return Value

void

at line line 245
void resource(string $name, string $controller, array $options = array())

Route a resource to a controller.

Parameters

string $name
string $controller
array $options

Return Value

void

at line line 264
void apiResource(string $name, string $controller, array $options = array())

Route an api resource to a controller.

Parameters

string $name
string $controller
array $options

Return Value

void

at line line 278
void group(array $attributes, Closure|string $routes)

Create a route group with shared attributes.

Parameters

array $attributes
Closure|string $routes

Return Value

void

at line line 311
array mergeWithLastGroup(array $new)

Merge the given array with the last group stack.

Parameters

array $new

Return Value

array

at line line 338
string getLastGroupPrefix()

Get the prefix from the last group on the stack.

Return Value

string

at line line 509
Response dispatch(Request $request)

Dispatch the request to the application.

Parameters

Request $request

Return Value

Response

at line line 522
mixed dispatchToRoute(Request $request)

Dispatch the request to a route and return the response.

Parameters

Request $request

Return Value

mixed

at line line 585
array gatherRouteMiddleware(Route $route)

Gather the middleware for the given route with resolved class names.

Parameters

Route $route

Return Value

array

at line line 612
Response prepareResponse(Request $request, mixed $response)

Create a response instance from the given value.

Parameters

Request $request
mixed $response

Return Value

Response

at line line 629
Route substituteBindings(Route $route)

Substitute the route bindings onto the route.

Parameters

Route $route

Return Value

Route

at line line 646
void substituteImplicitBindings(Route $route)

Substitute the implicit Eloquent model bindings for the route.

Parameters

Route $route

Return Value

void

at line line 670
void matched(string|callable $callback)

Register a route matched event listener.

Parameters

string|callable $callback

Return Value

void

at line line 680
array getMiddleware()

Get all of the defined middleware short-hand names.

Return Value

array

at line line 692
$this aliasMiddleware(string $name, string $class)

Register a short-hand name for a middleware.

Parameters

string $name
string $class

Return Value

$this

at line line 705
bool hasMiddlewareGroup(string $name)

Check if a middlewareGroup with the given name exists.

Parameters

string $name

Return Value

bool

at line line 715
array getMiddlewareGroups()

Get all of the defined middleware groups.

Return Value

array

at line line 727
$this middlewareGroup(string $name, array $middleware)

Register a group of middleware.

Parameters

string $name
array $middleware

Return Value

$this

at line line 743
$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.

Parameters

string $group
string $middleware

Return Value

$this

at line line 761
$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.

Parameters

string $group
string $middleware

Return Value

$this

at line line 781
void bind(string $key, string|callable $binder)

Add a new route parameter binder.

Parameters

string $key
string|callable $binder

Return Value

void

at line line 798
void model(string $key, string $class, Closure $callback = null)

Register a model binder for a wildcard.

Parameters

string $key
string $class
Closure $callback

Return Value

void

Exceptions

ModelNotFoundException

at line line 809
Closure getBindingCallback(string $key)

Get the binding callback for a given binding.

Parameters

string $key

Return Value

Closure

at line line 821
array getPatterns()

Get the global "where" patterns.

Return Value

array

at line line 833
void pattern(string $key, string $pattern)

Set a global where pattern on all routes.

Parameters

string $key
string $pattern

Return Value

void

at line line 844
void patterns(array $patterns)

Set a group of global where patterns on all routes.

Parameters

array $patterns

Return Value

void

at line line 856
bool hasGroupStack()

Determine if the router currently has a group stack.

Return Value

bool

at line line 866
array getGroupStack()

Get the current group stack for the router.

Return Value

array

at line line 878
mixed input(string $key, string $default = null)

Get a route parameter for the current route.

Parameters

string $key
string $default

Return Value

mixed

at line line 888
Request getCurrentRequest()

Get the request currently being dispatched.

Return Value

Request

at line line 898
Route getCurrentRoute()

Get the currently dispatched route instance.

Return Value

Route

at line line 908
Route current()

Get the currently dispatched route instance.

Return Value

Route

at line line 919
bool has(string $name)

Check if a route with the given name exists.

Parameters

string $name

Return Value

bool

at line line 929
string|null currentRouteName()

Get the current route name.

Return Value

string|null

at line line 939
bool is()

Alias for the "currentRouteNamed" method.

Return Value

bool

at line line 956
bool currentRouteNamed(string $name)

Determine if the current route matches a given name.

Parameters

string $name

Return Value

bool

at line line 966
string|null currentRouteAction()

Get the current route action.

Return Value

string|null

at line line 982
bool uses()

Alias for the "currentRouteUses" method.

Return Value

bool

at line line 999
bool currentRouteUses(string $action)

Determine if the current route action matches a given action.

Parameters

string $action

Return Value

bool

at line line 1009
void auth()

Register the typical authentication routes for an application.

Return Value

void

at line line 1033
void singularResourceParameters(bool $singular = true)

Set the unmapped global resource parameters to singular.

Parameters

bool $singular

Return Value

void

at line line 1044
void resourceParameters(array $parameters = array())

Set the global resource parameter mapping.

Parameters

array $parameters

Return Value

void

at line line 1055
array|null resourceVerbs(array $verbs = array())

Get or set the verbs used in the resource URIs.

Parameters

array $verbs

Return Value

array|null

at line line 1065
RouteCollection getRoutes()

Get the underlying route collection.

Return Value

RouteCollection

at line line 1076
void setRoutes(RouteCollection $routes)

Set the route collection instance.

Parameters

RouteCollection $routes

Return Value

void