W3cubDocs

/Laravel 5.1

Router

class Router implements Registrar (View source)

Traits

Macroable

Properties

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 = array())

Route a controller to a URI with wildcard routing.

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 group( array $attributes, Closure $callback)

Create a route group with shared 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.

string getLastGroupPrefix()

Get the prefix from the last group on the stack.

Response dispatch( Request $request)

Dispatch the request to the application.

mixed dispatchToRoute( Request $request)

Dispatch the request to a route and return the response.

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.

void matched( string|callable $callback)

Register a route matched event listener.

void before( string|callable $callback)

Register a new "before" filter with the router.

void after( string|callable $callback)

Register a new "after" 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)

Register a new filter with the router.

void when( string $pattern, string $name, array|null $methods = null)

Register a pattern-based filter with the router.

void whenRegex( string $pattern, string $name, array|null $methods = null)

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 callRouteBefore( Route $route, Request $request)

Call the given route's before filters.

array findPatternFilters( Request $request)

Find the patterned filters matching a request.

mixed callRouteAfter( Route $route, Request $request, Response $response)

Call the given route's after filters.

mixed callRouteFilter( string $filter, array $parameters, Route $route, Request $request, Response|null $response = null)

Call the given route filter.

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.

Parameters

string $name
callable $macro

Return Value

void

static bool hasMacro( string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic( string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call( string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

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

Create a new Router instance.

Parameters

Dispatcher $events
Container $container

Return Value

void

void get( string $uri, Closure|array|string $action)

Register a new GET route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

void

void post( string $uri, Closure|array|string $action)

Register a new POST route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

void

void put( string $uri, Closure|array|string $action)

Register a new PUT route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

void

void patch( string $uri, Closure|array|string $action)

Register a new PATCH route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

void

void delete( string $uri, Closure|array|string $action)

Register a new DELETE route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

void

void options( string $uri, Closure|array|string $action)

Register a new OPTIONS route with the router.

Parameters

string $uri
Closure|array|string $action

Return Value

void

Route any( string $uri, Closure|array|string $action)

Register a new route responding to all verbs.

Parameters

string $uri
Closure|array|string $action

Return Value

Route

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

Register a new route with the given verbs.

Parameters

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

Return Value

void

void controllers( array $controllers)

Register an array of controllers with wildcard routing.

Parameters

array $controllers

Return Value

void

void controller( string $uri, string $controller, array $names = array())

Route a controller to a URI with wildcard routing.

Parameters

string $uri
string $controller
array $names

Return Value

void

void resources( array $resources)

Register an array of resource controllers.

Parameters

array $resources

Return Value

void

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

void group( array $attributes, Closure $callback)

Create a route group with shared attributes.

Parameters

array $attributes
Closure $callback

Return Value

void

array mergeWithLastGroup( array $new)

Merge the given array with the last group stack.

Parameters

array $new

Return Value

array

static array mergeGroup( array $new, array $old)

Merge the given group attributes.

Parameters

array $new
array $old

Return Value

array

string getLastGroupPrefix()

Get the prefix from the last group on the stack.

Return Value

string

Response dispatch( Request $request)

Dispatch the request to the application.

Parameters

Request $request

Return Value

Response

mixed dispatchToRoute( Request $request)

Dispatch the request to a route and return the response.

Parameters

Request $request

Return Value

mixed

array gatherRouteMiddlewares( Route $route)

Gather the middleware for the given route.

Parameters

Route $route

Return Value

array

string resolveMiddlewareClassName( string $name)

Resolve the middleware name to a class name preserving passed parameters.

Parameters

string $name

Return Value

string

void matched( string|callable $callback)

Register a route matched event listener.

Parameters

string|callable $callback

Return Value

void

void before( string|callable $callback)

Register a new "before" filter with the router.

Parameters

string|callable $callback

Return Value

void

void after( string|callable $callback)

Register a new "after" filter with the router.

Parameters

string|callable $callback

Return Value

void

array getMiddleware()

Get all of the defined middleware short-hand names.

Return Value

array

$this middleware( string $name, string $class)

Register a short-hand name for a middleware.

Parameters

string $name
string $class

Return Value

$this

void filter( string $name, string|callable $callback)

Register a new filter with the router.

Parameters

string $name
string|callable $callback

Return Value

void

void when( string $pattern, string $name, array|null $methods = null)

Register a pattern-based filter with the router.

Parameters

string $pattern
string $name
array|null $methods

Return Value

void

void whenRegex( string $pattern, string $name, array|null $methods = null)

Register a regular expression based filter with the router.

Parameters

string $pattern
string $name
array|null $methods

Return Value

void

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

NotFoundHttpException

void bind( string $key, string|callable $binder)

Add a new route parameter binder.

Parameters

string $key
string|callable $binder

Return Value

void

Closure createClassBinding( string $binding)

Create a class based binding using the IoC container.

Parameters

string $binding

Return Value

Closure

void pattern( string $key, string $pattern)

Set a global where pattern on all routes.

Parameters

string $key
string $pattern

Return Value

void

void patterns( array $patterns)

Set a group of global where patterns on all routes.

Parameters

array $patterns

Return Value

void

mixed callRouteBefore( Route $route, Request $request)

Call the given route's before filters.

Parameters

Route $route
Request $request

Return Value

mixed

array findPatternFilters( Request $request)

Find the patterned filters matching a request.

Parameters

Request $request

Return Value

array

mixed callRouteAfter( Route $route, Request $request, Response $response)

Call the given route's after filters.

Parameters

Route $route
Request $request
Response $response

Return Value

mixed

mixed callRouteFilter( string $filter, array $parameters, Route $route, Request $request, Response|null $response = null)

Call the given route filter.

Parameters

string $filter
array $parameters
Route $route
Request $request
Response|null $response

Return Value

mixed

Response prepareResponse( Request $request, mixed $response)

Create a response instance from the given value.

Parameters

Request $request
mixed $response

Return Value

Response

bool hasGroupStack()

Determine if the router currently has a group stack.

Return Value

bool

array getGroupStack()

Get the current group stack for the router.

Return Value

array

mixed input( string $key, string $default = null)

Get a route parameter for the current route.

Parameters

string $key
string $default

Return Value

mixed

Route getCurrentRoute()

Get the currently dispatched route instance.

Return Value

Route

Route current()

Get the currently dispatched route instance.

Return Value

Route

bool has( string $name)

Check if a route with the given name exists.

Parameters

string $name

Return Value

bool

string|null currentRouteName()

Get the current route name.

Return Value

string|null

bool is()

Alias for the "currentRouteNamed" method.

Return Value

bool

bool currentRouteNamed( string $name)

Determine if the current route matches a given name.

Parameters

string $name

Return Value

bool

string|null currentRouteAction()

Get the current route action.

Return Value

string|null

bool uses()

Alias for the "currentRouteUses" method.

Return Value

bool

bool currentRouteUses( string $action)

Determine if the current route action matches a given action.

Parameters

string $action

Return Value

bool

Request getCurrentRequest()

Get the request currently being dispatched.

Return Value

Request

RouteCollection getRoutes()

Get the underlying route collection.

Return Value

RouteCollection

void setRoutes( RouteCollection $routes)

Set the route collection instance.

Parameters

RouteCollection $routes

Return Value

void

array getPatterns()

Get the global "where" patterns.

Return Value

array

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.1/Illuminate/Routing/Router.html