Adding multiple middleware to a Laravel route

Per https://laravel.com/docs/5.3/routing#route-groups , I can add auth middleware as follows:

 Route::group(['middleware' => 'auth'], function () { Route::get('/', function () { // Uses Auth Middleware }); Route::get('user/profile', function () { // Uses Auth Middleware }); }); 

I also noticed that middleware was added as follows:

 Route::group(['middleware' => ['web']], function() { // Uses all Middleware $middlewareGroups['web'] located in /app/Http/kernel.php? Route::resource('blog','BlogController'); //Make a CRUD controller }); 

How can I do both?

PS. Any comments that give an idea of ​​what the bottom four lines of code are doing will be appreciated.

+6
source share
1 answer

To assign middleware for a route, you can use one middleware (first code snippet) or middleware groups (second code snippet). With middleware groups, you simultaneously assign multiple middlewares. More information about middleware groups can be found here: https://laravel.com/docs/5.3/middleware#middleware-groups

To use both (one intermediate and intermediate), you can try the following:

 Route::group(['middleware' => ['auth', 'web']], function() { // uses 'auth' middleware plus all middleware from $middlewareGroups['web'] Route::resource('blog','BlogController'); //Make a CRUD controller }); 
+7
source

Source: https://habr.com/ru/post/1012678/


All Articles