UrlGenerator

class UrlGenerator (View source)

Properties

protected RouteCollection $routes The route collection.
protected Request $request The request instance.
protected string $forcedRoot The force URL root.
protected string $forceSchema The forced schema for URLs.
protected array $dontEncode Characters that should not be URL encoded.

Methods

void __construct(RouteCollection $routes, Request $request)

Create a new URL Generator instance.

string full()

Get the full URL for the current request.

string current()

Get the current URL for the request.

string previous()

Get the URL for the previous request.

string to(string $path, mixed $extra = array(), bool|null $secure = null)

Generate a absolute URL to the given path.

string secure(string $path, array $parameters = array())

Generate a secure, absolute URL to the given path.

string asset(string $path, bool|null $secure = null)

Generate a URL to an application asset.

string removeIndex(string $root)

Remove the index.php file from a path.

string secureAsset(string $path)

Generate a URL to a secure asset.

string getScheme(bool|null $secure)

Get the scheme for a raw URL.

void forceSchema(string $schema)

Force the schema for URLs.

string route(string $name, mixed $parameters = array(), bool $absolute = true, Route $route = null)

Get the URL to a named route.

string toRoute(Route $route, array $parameters, bool $absolute)

Get the URL for a given route instance.

string replaceRoot(Route $route, string $domain, array $parameters)

Replace the parameters on the root path.

string replaceRouteParameters(string $path, array $parameters)

Replace all of the wildcard parameters for a route path.

string replaceNamedParameters(string $path, array $parameters)

Replace all of the named parameters in the path.

string getRouteQueryString(array $parameters)

Get the query string for a given route.

array getStringParameters(array $parameters)

Get the string parameters from a given list.

array getNumericParameters(array $parameters)

Get the numeric parameters from a given list.

string getRouteDomain(Route $route, array $parameters)

Get the formatted domain for a given route.

string formatDomain(Route $route, array $parameters)

Format the domain and port for the route and request.

string getDomainAndScheme(Route $route)

Get the domain and scheme for the route.

string addPortToDomain(string $domain)

Add the port to the domain if necessary.

string getRouteRoot(Route $route, string $domain)

Get the root of the route URL.

string getRouteScheme(Route $route)

Get the scheme for the given route.

string action(string $action, mixed $parameters = array(), bool $absolute = true)

Get the URL to a controller action.

string getRootUrl(string $scheme, string $root = null)

Get the base URL for the request.

void forceRootUrl(string $root)

Set the forced root URL.

bool isValidUrl(string $path)

Determine if the given path is a valid URL.

string trimUrl(string $root, string $path, string $tail = '')

Format the given URL segments into a single URL.

Request getRequest()

Get the request instance.

void setRequest(Request $request)

Set the current request instance.

Details

void __construct(RouteCollection $routes, Request $request)

Create a new URL Generator instance.

Parameters

RouteCollection $routes
Request $request

Return Value

void

string full()

Get the full URL for the current request.

Return Value

string

string current()

Get the current URL for the request.

Return Value

string

string previous()

Get the URL for the previous request.

Return Value

string

string to(string $path, mixed $extra = array(), bool|null $secure = null)

Generate a absolute URL to the given path.

Parameters

string $path
mixed $extra
bool|null $secure

Return Value

string

string secure(string $path, array $parameters = array())

Generate a secure, absolute URL to the given path.

Parameters

string $path
array $parameters

Return Value

string

string asset(string $path, bool|null $secure = null)

Generate a URL to an application asset.

Parameters

string $path
bool|null $secure

Return Value

string

protected string removeIndex(string $root)

Remove the index.php file from a path.

Parameters

string $root

Return Value

string

string secureAsset(string $path)

Generate a URL to a secure asset.

Parameters

string $path

Return Value

string

protected string getScheme(bool|null $secure)

Get the scheme for a raw URL.

Parameters

bool|null $secure

Return Value

string

void forceSchema(string $schema)

Force the schema for URLs.

Parameters

string $schema

Return Value

void

string route(string $name, mixed $parameters = array(), bool $absolute = true, Route $route = null)

Get the URL to a named route.

Parameters

string $name
mixed $parameters
bool $absolute
Route $route

Return Value

string

Exceptions

InvalidArgumentException

protected string toRoute(Route $route, array $parameters, bool $absolute)

Get the URL for a given route instance.

Parameters

Route $route
array $parameters
bool $absolute

Return Value

string

protected string replaceRoot(Route $route, string $domain, array $parameters)

Replace the parameters on the root path.

Parameters

Route $route
string $domain
array $parameters

Return Value

string

protected string replaceRouteParameters(string $path, array $parameters)

Replace all of the wildcard parameters for a route path.

Parameters

string $path
array $parameters

Return Value

string

protected string replaceNamedParameters(string $path, array $parameters)

Replace all of the named parameters in the path.

Parameters

string $path
array $parameters

Return Value

string

protected string getRouteQueryString(array $parameters)

Get the query string for a given route.

Parameters

array $parameters

Return Value

string

protected array getStringParameters(array $parameters)

Get the string parameters from a given list.

Parameters

array $parameters

Return Value

array

protected array getNumericParameters(array $parameters)

Get the numeric parameters from a given list.

Parameters

array $parameters

Return Value

array

protected string getRouteDomain(Route $route, array $parameters)

Get the formatted domain for a given route.

Parameters

Route $route
array $parameters

Return Value

string

protected string formatDomain(Route $route, array $parameters)

Format the domain and port for the route and request.

Parameters

Route $route
array $parameters

Return Value

string

protected string getDomainAndScheme(Route $route)

Get the domain and scheme for the route.

Parameters

Route $route

Return Value

string

protected string addPortToDomain(string $domain)

Add the port to the domain if necessary.

Parameters

string $domain

Return Value

string

protected string getRouteRoot(Route $route, string $domain)

Get the root of the route URL.

Parameters

Route $route
string $domain

Return Value

string

protected string getRouteScheme(Route $route)

Get the scheme for the given route.

Parameters

Route $route

Return Value

string

string action(string $action, mixed $parameters = array(), bool $absolute = true)

Get the URL to a controller action.

Parameters

string $action
mixed $parameters
bool $absolute

Return Value

string

protected string getRootUrl(string $scheme, string $root = null)

Get the base URL for the request.

Parameters

string $scheme
string $root

Return Value

string

void forceRootUrl(string $root)

Set the forced root URL.

Parameters

string $root

Return Value

void

bool isValidUrl(string $path)

Determine if the given path is a valid URL.

Parameters

string $path

Return Value

bool

protected string trimUrl(string $root, string $path, string $tail = '')

Format the given URL segments into a single URL.

Parameters

string $root
string $path
string $tail

Return Value

string

Request getRequest()

Get the request instance.

Return Value

Request

void setRequest(Request $request)

Set the current request instance.

Parameters

Request $request

Return Value

void

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