urls.md 2.24 KB
Newer Older
Taylor Otwell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
# Generating URLs

## Contents

- [The Basics](#the-basics)
- [URLs To Routes](#urls-to-routes)
- [URLs To Controller Actions](#urls-to-controller-actions)
- [URLs To Assets](#urls-to-assets)
- [URL Helpers](#url-helpers)

<a name="the-basics"></a>
## The Basics

#### Retrieving the application's base URL:

	$url = URL::base();

#### Generating a URL relative to the base URL:

	$url = URL::to('user/profile');

#### Generating a HTTPS URL:

	$url = URL::to_secure('user/login');

#### Retrieving the current URL:

	$url = URL::current();

#### Retrieving the current URL including query string:

	$url = URL::full();

<a name="urls-to-routes"></a>
## URLs To Routes

#### Generating a URL to a named route:

	$url = URL::to_route('profile');

Sometimes you may need to generate a URL to a named route, but also need to specify the values that should be used instead of the route's URI wildcards. It's easy to replace the wildcards with proper values:

#### Generating a URL to a named route with wildcard values:

	$url = URL::to_route('profile', array($username));

*Further Reading:*

- [Named Routes](/docs/routing#named-routes)

<a name="urls-to-controller-actions"></a>
## URLs To Controller Actions

#### Generating a URL to a controller action:

	$url = URL::to_action('user@profile');

#### Generating a URL to an action with wildcard values:

	$url = URL::to_action('user@profile', array($username));

<a name="urls-to-assets"></a>
## URLs To Assets

URLs generated for assets will not contain the "application.index" configuration option.

#### Generating a URL to an asset:

	$url = URL::to_asset('js/jquery.js');

<a name="url-helpers"></a>
## URL Helpers

There are several global functions for generating URLs designed to make your life easier and your code cleaner:

#### Generating a URL relative to the base URL:

	$url = url('user/profile');

#### Generating a URL to an asset:

	$url = asset('js/jquery.js');

#### Generating a URL to a named route:

	$url = route('profile');

#### Generating a URL to a named route with wildcard values:

	$url = route('profile', array($username));

#### Generating a URL to a controller action:

	$url = action('user@profile');

#### Generating a URL to an action with wildcard values:

	$url = action('user@profile', array($username));