29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

HTTP Routing 61<br />

.<br />

1 Route::group(['middleware' => 'auth'], function () {<br />

2 Route::get('/', function () {<br />

3 // Uses Auth Middleware<br />

4 });<br />

5<br />

6 Route::get('user/profile', function () {<br />

7 // Uses Auth Middleware<br />

8 });<br />

9 });<br />

Namespaces<br />

Another common use-case for route groups is assigning the same PHP namespace to a group of<br />

controllers. You may use the namespace parameter in your group attribute array to specify the<br />

namespace for all controllers within the group:<br />

.<br />

1 Route::group(['namespace' => 'Admin'], function()<br />

2 {<br />

3 // Controllers Within The "App\Http\Controllers\Admin" Namespace<br />

4<br />

5 Route::group(['namespace' => 'User'], function()<br />

6 {<br />

7 // Controllers Within The "App\Http\Controllers\Admin\User" Namespace<br />

8 });<br />

9 });<br />

Remember, by default, the RouteServiceProvider includes your routes.php file within a namespace<br />

group, allowing you to register controller routes without specifying the full App\Http\Controllers<br />

namespace prefix. So, we only need to specify the portion of the namespace that comes after the base<br />

App\Http\Controllers namespace root.<br />

Sub-Domain Routing<br />

Route groups may also be used to route wildcard sub-domains. Sub-domains may be assigned route<br />

parameters just like route URIs, allowing you to capture a portion of the sub-domain for usage<br />

in your route or controller. The sub-domain may be specified using the domain key on the group<br />

attribute array:

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

Saved successfully!

Ooh no, something went wrong!