29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

HTTP Routing 60<br />

Generating URLs To Named Routes<br />

Once you have assigned a name to a given route, you may use the route’s name when generating<br />

URLs or redirects via the route function:<br />

.<br />

1 $url = route('profile');<br />

2<br />

3 $redirect = redirect()->route('profile');<br />

If the route defines parameters, you may pass the parameters as the second argument to the route<br />

method. The given parameters will automatically be inserted into the URL:<br />

.<br />

1 Route::get('user/{id}/profile', ['as' => 'profile', function ($id) {<br />

2 //<br />

3 }]);<br />

4<br />

5 $url = route('profile', ['id' => 1]);<br />

Route Groups<br />

Route groups allow you to share route attributes, such as middleware or namespaces, across a<br />

large number of routes without needing to define those attributes on each individual routes. Shared<br />

attributes are specified in an array format as the first parameter to the Route::group method.<br />

To learn more about route groups, we’ll walk through several common use-cases for the feature.<br />

Middleware<br />

To assign middleware to all routes within a group, you may use the middleware key in the group<br />

attribute array. Middleware will be executed in the order you define this array:<br />

.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!