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 58<br />

.<br />

1 Route::get('user/{name}', function ($name) {<br />

2 //<br />

3 })<br />

4 ->where('name', '[A-Za-z]+');<br />

5<br />

6 Route::get('user/{id}', function ($id) {<br />

7 //<br />

8 })<br />

9 ->where('id', '[0-9]+');<br />

10<br />

11 Route::get('user/{id}/{name}', function ($id, $name) {<br />

12 //<br />

13 })<br />

14 ->where(['id' => '[0-9]+', 'name' => '[a-z]+']);<br />

Global Constraints<br />

If you would like a route parameter to always be constrained by a given regular expression,<br />

you may use the pattern method. You should define these patterns in the boot method of your<br />

RouteServiceProvider:<br />

.<br />

1 /**<br />

2 * Define your route model bindings, pattern filters, etc.<br />

3 *<br />

4 * @param \Illuminate\Routing\Router $router<br />

5 * @return void<br />

6 */<br />

7 public function boot(Router $router)<br />

8 {<br />

9 $router->pattern('id', '[0-9]+');<br />

10<br />

11 parent::boot($router);<br />

12 }<br />

Once the pattern has been defined, it is automatically applied to all routes using that parameter<br />

name:

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

Saved successfully!

Ooh no, something went wrong!