php - API Throttle in Laravel 5.2 -


i seeing this tutorial throttle in laravel 5.2

it seems throttle used apis, why couldn't used other controller stuff, avoid people send 100 times same form through postman.

i tell that, because in kernel.php, now, middleware divided between web , apis: kernel.php:laravel 5.2

you can apply web pages well. judging comments, you're confused new features of middleware, middleware groups.

5.2 brought along way group middleware route groups before. in 5.1 like:

route::group(['prefix' => 'api', 'middleware'=>'auth,custom_middleware,permission:edit_permissions'], function() {     route::post('permissions/{id}/store', ['uses'=>'permissioncontroller@store']); }); 

that still valid, if wanted add route group same middleware, had either juggle organization nested beneath single route group applied middleware or had copy paste middleware, neither desirable. 5.2, have this:

kernel.php  protected $middlewaregroups = [     'permissions_api' => [          'auth',           'custom_middleware',          'permission:edit_permissions',      ] ];  routes.php  route::group(['middleware' => ['permissions_api']], function () {     route::post('permissions/{id}/store', ['uses'=>'permissioncontroller@store']); });  route::group(['middleware' => ['permissions_api']], function () {     route::post('permissions/{id}/update', ['uses'=>'permissioncontroller@update']); }); 

so can group middleware , apply them in groups. that's api , web seeing is. it's default middleware groups provided laravel can modify want. throttle available middleware ever may need it. below both valid

route::group(['middleware' => ['throttle:60,1']], function () {     route::post('permissions/{id}/update', ['uses'=>'permissioncontroller@update']); }); 

or

protected $middlewaregroups = [     'permissions_api' => [          'auth',           'custom_middleware',          'permission:edit_permissions',          'throttle:60,1'      ]  ]; 

so throttle middleware , can applied middleware is. defined in kernel.php 'throttle' => \illuminate\routing\middleware\throttlerequests::class, , 60,1 middleware parameters, added in 5.1


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -