sakhunzai
sakhunzai

Reputation: 14500

Understanding laravel 'auth' and 'web' middleware

I have strange behavior on one of route groups I have defined e.g

Route::group(['prefix' => 'admin', 'middleware' => ['web','auth']], function (){
  //admin routes
 }
);

Whenever I defined 'middleware' => ['web','auth'], routes are accessible after login , but without 'web' I am redirected to / home.

What I thought was that , 'web' is default middleware injected ,please correct me if I am wrong. Otherwise there is some other setting that is affecting this behavior ?

Upvotes: 2

Views: 12943

Answers (2)

sakhunzai
sakhunzai

Reputation: 14500

The web middleware is default now, but if you have create laravel app skeleton a while ago you have to update the route provider . You can see the changes in this diff

Upvotes: 3

Hiren Makwana
Hiren Makwana

Reputation: 2156

Laravel comes with web middleware groups that contains common middleware you may want to apply to web UI routes. the web middleware group is automatically applied to your default routes.php file by the RouteServiceProvider.

Upvotes: 4

Related Questions