06.10.2016 Views

laravel-5

Create successful ePaper yourself

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

Release Notes 6<br />

building a web UI and an API within the same application. You may group the session and CSRF<br />

routes into a web group, and perhaps the rate limiter in the api group.<br />

In fact, the default Laravel 5.2 application structure takes exactly this approach. For example, in the<br />

default App\Http\Kernel.php file you will find the following:<br />

1 /**<br />

2 * The application's route middleware groups.<br />

3 *<br />

4 * @var array<br />

5 */<br />

6 protected $middlewareGroups = [<br />

7 'web' => [<br />

8 \App\Http\Middleware\EncryptCookies::class,<br />

9 \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,<br />

10 \Illuminate\Session\Middleware\StartSession::class,<br />

11 \Illuminate\View\Middleware\ShareErrorsFromSession::class,<br />

12 \App\Http\Middleware\VerifyCsrfToken::class,<br />

13 ],<br />

14<br />

15 'api' => [<br />

16 'throttle:60,1',<br />

17 ],<br />

18 ];<br />

Then, the web group may be assigned to routes like so:<br />

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

2 //<br />

3 });<br />

However, keep in mind the web middleware group is already applied to your routes by default since<br />

the RouteServiceProvider includes it in the default middleware group.<br />

Rate Limiting<br />

A new rate limiter middleware is now included with the framework, allowing you to easily limit the<br />

number of requests that a given IP address can make to a route over a specified number of minutes.<br />

For example, to limit a route to 60 requests every minute from a single IP address, you may do the<br />

following:

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

Saved successfully!

Ooh no, something went wrong!