class Illuminate / Routing / Router

Router

Implements

Uses

Properties

protected

$events Dispatcher

The event dispatcher instance.

Default: null
protected

$container Container

The IoC container instance.

Default: null
protected

$routes RouteCollectionInterface

The route collection instance.

Default: null
protected

$current Route |null

The currently dispatched route instance.

Default: null
protected

$currentRequest Request

The request currently being dispatched.

Default: null
protected

$middleware array

All of the short-hand keys for middlewares.

Default: []
protected

$middlewareGroups array

All of the middleware groups.

Default: []
public

$middlewarePriority array

The priority-sorted list of middleware.

Forces the listed middleware to always be in the given order.

Default: []
protected

$binders array

The registered route value binders.

Default: []
protected

$patterns array

The globally available parameter patterns.

Default: []
protected

$groupStack array

The route group attribute stack.

Default: []
public static

$verbs string[]

All of the verbs supported by the router.

Default: array

Methods

public

__construct ( Dispatcher $events , Container $container ) : void

Create a new Router instance.

Parameters

public

get ( $uri , $action ) : Route

Register a new GET route with the router.

Parameters

  • $uri string
  • $action array|string|callable|null
public

post ( $uri , $action ) : Route

Register a new POST route with the router.

Parameters

  • $uri string
  • $action array|string|callable|null
public

put ( $uri , $action ) : Route

Register a new PUT route with the router.

Parameters

  • $uri string
  • $action array|string|callable|null
public

patch ( $uri , $action ) : Route

Register a new PATCH route with the router.

Parameters

  • $uri string
  • $action array|string|callable|null
public

delete ( $uri , $action ) : Route

Register a new DELETE route with the router.

Parameters

  • $uri string
  • $action array|string|callable|null
public

options ( $uri , $action ) : Route

Register a new OPTIONS route with the router.

Parameters

  • $uri string
  • $action array|string|callable|null
public

any ( $uri , $action ) : Route

Register a new route responding to all verbs.

Parameters

  • $uri string
  • $action array|string|callable|null
public

fallback ( $action ) : Route

Register a new fallback route with the router.

Parameters

  • $action array|string|callable|null
public

redirect ( $uri , $destination , $status ) : Route

Create a redirect from one URI to another.

Parameters

  • $uri string
  • $destination string
  • $status int
public

permanentRedirect ( $uri , $destination ) : Route

Create a permanent redirect from one URI to another.

Parameters

  • $uri string
  • $destination string
public

view ( $uri , $view , $data , $status , array $headers ) : Route

Register a new route that returns a view.

Parameters

  • $uri string
  • $view string
  • $data array
  • $status int|array
  • $headers array
public

match ( $methods , $uri , $action ) : Route

Register a new route with the given verbs.

Parameters

  • $methods array|string
  • $uri string
  • $action array|string|callable|null
public

resources ( array $resources , array $options ) : void

Register an array of resource controllers.

Parameters

  • $resources array
  • $options array
public

resource ( $name , $controller , array $options ) : PendingResourceRegistration

Route a resource to a controller.

Parameters

  • $name string
  • $controller string
  • $options array
public

apiResources ( array $resources , array $options ) : void

Register an array of API resource controllers.

Parameters

  • $resources array
  • $options array
public

apiResource ( $name , $controller , array $options ) : PendingResourceRegistration

Route an API resource to a controller.

Parameters

  • $name string
  • $controller string
  • $options array
public

singletons ( array $singletons , array $options ) : void

Register an array of singleton resource controllers.

Parameters

  • $singletons array
  • $options array
public

singleton ( $name , $controller , array $options ) : PendingSingletonResourceRegistration

Route a singleton resource to a controller.

Parameters

  • $name string
  • $controller string
  • $options array
public

apiSingletons ( array $singletons , array $options ) : void

Register an array of API singleton resource controllers.

Parameters

  • $singletons array
  • $options array
public

apiSingleton ( $name , $controller , array $options ) : PendingSingletonResourceRegistration

Route an API singleton resource to a controller.

Parameters

  • $name string
  • $controller string
  • $options array
public

group ( array $attributes , $routes ) : $this

Create a route group with shared attributes.

Parameters

  • $attributes array
  • $routes Closure |array|string
protected

updateGroupStack ( array $attributes ) : void

Update the group stack with the given attributes.

Parameters

  • $attributes array
public

mergeWithLastGroup ( $new , $prependExistingPrefix ) : array

Merge the given array with the last group stack.

Parameters

  • $new array
  • $prependExistingPrefix bool
protected

loadRoutes ( $routes ) : void

Load the provided routes.

Parameters

public

getLastGroupPrefix ( ) : string

Get the prefix from the last group on the stack.

public

addRoute ( $methods , $uri , $action ) : Route

Add a route to the underlying route collection.

Parameters

  • $methods array|string
  • $uri string
  • $action array|string|callable|null
protected

createRoute ( $methods , $uri , $action ) : Route

Create a new route instance.

Parameters

  • $methods array|string
  • $uri string
  • $action mixed
protected

actionReferencesController ( $action ) : bool

Determine if the action is routing to a controller.

Parameters

  • $action mixed
protected

convertToControllerAction ( $action ) : array

Add a controller based route action to the action array.

Parameters

  • $action array|string
protected

prependGroupNamespace ( $class ) : string

Prepend the last group namespace onto the use clause.

Parameters

  • $class string
protected

prependGroupController ( $class ) : string

Prepend the last group controller onto the use clause.

Parameters

  • $class string
public

newRoute ( $methods , $uri , $action ) : Route

Create a new Route object.

Parameters

  • $methods array|string
  • $uri string
  • $action mixed
protected

prefix ( $uri ) : string

Prefix the given URI with the last prefix.

Parameters

  • $uri string
protected

addWhereClausesToRoute ( $route ) : Route

Add the necessary where clauses to the route based on its initial registration.

Parameters

protected

mergeGroupAttributesIntoRoute ( $route ) : void

Merge the group stack with the controller action.

Parameters

public

respondWithRoute ( $name ) : Symfony\...\Response

Return the response returned by the given route.

Parameters

  • $name string
public

dispatch ( Request $request ) : Symfony\...\Response

Dispatch the request to the application.

Parameters

public

dispatchToRoute ( Request $request ) : Symfony\...\Response

Dispatch the request to a route and return the response.

Parameters

protected

findRoute ( $request ) : Route

Find the route matching a given request.

Parameters

protected

runRoute ( Request $request , Route $route ) : Symfony\...\Response

Return the response for the given route.

Parameters

protected

runRouteWithinStack ( Route $route , Request $request ) : mixed

Run the given route within a Stack "onion" instance.

Parameters

public

gatherRouteMiddleware ( Route $route ) : array

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

Parameters

public

resolveMiddleware ( array $middleware , array $excluded ) : array

Resolve a flat array of middleware classes from the provided array.

Parameters

  • $middleware array
  • $excluded array
protected

sortMiddleware ( Illuminate\...\Collection $middlewares ) : array

Sort the given middleware by priority.

Parameters

  • $middlewares Illuminate\...\Collection
public

prepareResponse ( $request , $response ) : Symfony\...\Response

Create a response instance from the given value.

Parameters

  • $request Symfony\...\Request
  • $response mixed
public static

toResponse ( $request , $response ) : Symfony\...\Response

Static version of prepareResponse.

Parameters

  • $request Symfony\...\Request
  • $response mixed
public

substituteBindings ( $route ) : Route

Substitute the route bindings onto the route.

Parameters

public

substituteImplicitBindings ( $route ) : void

Substitute the implicit route bindings for the given route.

Parameters

protected

performBinding ( $key , $value , $route ) : mixed

Call the binding callback for the given key.

Parameters

  • $key string
  • $value string
  • $route Route
public

matched ( $callback ) : void

Register a route matched event listener.

Parameters

  • $callback string|callable
public

getMiddleware ( ) : array

Get all of the defined middleware short-hand names.

public

aliasMiddleware ( $name , $class ) : $this

Register a short-hand name for a middleware.

Parameters

  • $name string
  • $class string
public

hasMiddlewareGroup ( $name ) : bool

Check if a middlewareGroup with the given name exists.

Parameters

  • $name string
public

getMiddlewareGroups ( ) : array

Get all of the defined middleware groups.

public

middlewareGroup ( $name , array $middleware ) : $this

Register a group of middleware.

Parameters

  • $name string
  • $middleware array
public

prependMiddlewareToGroup ( $group , $middleware ) : $this

Add a middleware to the beginning of a middleware group.

Parameters

  • $group string
  • $middleware string
public

pushMiddlewareToGroup ( $group , $middleware ) : $this

Add a middleware to the end of a middleware group.

Parameters

  • $group string
  • $middleware string
public

removeMiddlewareFromGroup ( $group , $middleware ) : $this

Remove the given middleware from the specified group.

Parameters

  • $group string
  • $middleware string
public

flushMiddlewareGroups ( ) : $this

Flush the router's middleware groups.

public

bind ( $key , $binder ) : void

Add a new route parameter binder.

Parameters

  • $key string
  • $binder string|callable
public

model ( $key , $class , Closure $callback ) : void

Register a model binder for a wildcard.

Parameters

  • $key string
  • $class string
  • $callback Closure |null
public

getBindingCallback ( $key ) : Closure |null

Get the binding callback for a given binding.

Parameters

  • $key string
public

getPatterns ( ) : array

Get the global "where" patterns.

public

pattern ( $key , $pattern ) : void

Set a global where pattern on all routes.

Parameters

  • $key string
  • $pattern string
public

patterns ( $patterns ) : void

Set a group of global where patterns on all routes.

Parameters

  • $patterns array
public

hasGroupStack ( ) : bool

Determine if the router currently has a group stack.

public

getGroupStack ( ) : array

Get the current group stack for the router.

public

input ( $key , $default ) : mixed

Get a route parameter for the current route.

Parameters

  • $key string
  • $default string|null
public

getCurrentRequest ( ) : Request

Get the request currently being dispatched.

public

getCurrentRoute ( ) : Route |null

Get the currently dispatched route instance.

public

current ( ) : Route |null

Get the currently dispatched route instance.

public

has ( $name ) : bool

Check if a route with the given name exists.

Parameters

  • $name string|array
public

currentRouteName ( ) : string|null

Get the current route name.

public

is ( $patterns ) : bool

Alias for the "currentRouteNamed" method.

Parameters

  • $patterns mixed
public

currentRouteNamed ( $patterns ) : bool

Determine if the current route matches a pattern.

Parameters

  • $patterns mixed
public

currentRouteAction ( ) : string|null

Get the current route action.

public

uses ( $patterns ) : bool

Alias for the "currentRouteUses" method.

Parameters

  • $patterns array
public

currentRouteUses ( $action ) : bool

Determine if the current route action matches a given action.

Parameters

  • $action string
public

singularResourceParameters ( $singular ) : void

Set the unmapped global resource parameters to singular.

Parameters

  • $singular bool
public

resourceParameters ( array $parameters ) : void

Set the global resource parameter mapping.

Parameters

  • $parameters array
public

resourceVerbs ( array $verbs ) : array|null

Get or set the verbs used in the resource URIs.

Parameters

  • $verbs array
public

getRoutes ( ) : RouteCollectionInterface

Get the underlying route collection.

public

setRoutes ( RouteCollection $routes ) : void

Set the route collection instance.

Parameters

public

setCompiledRoutes ( array $routes ) : void

Set the compiled route collection instance.

Parameters

  • $routes array
public static

uniqueMiddleware ( array $middleware ) : array

Remove any duplicate middleware from the given array.

Parameters

  • $middleware array
public

setContainer ( Container $container ) : $this

Set the container instance used by the router.

Parameters

public

__call ( $method , $parameters ) : mixed

Dynamically handle calls into the router instance.

Parameters

  • $method string
  • $parameters array