TarikAli
2 months ago
296
1
Laravel

auth and web Middleware (check user logged in)

Posted 2 months ago by TarikAli

Hello , i'm confused between

\Illuminate\Auth\Middleware\Authenticate::class

and

'auth' => \App\Http\Middleware\Authenticate::class

case 1 : in Kernal.php some one add admin middlewareGroup under $middlewareGroups

'web' => [.....],
'admin' => [
      	\Illuminate\Auth\Middleware\Authenticate::class,
		],
'api' => [....],

and in routes :

Route::group([
		'middleware' => ['admin']
], function ($router) {......}

so Admin will execute \Illuminate\Auth\Middleware\Authenticate::class to check if user logged in

case 2 in laravel docs just use auth:

Route::group([
		'middleware' => ['auth']
], function ($router) {......}

what is the difference ? what is the right way to protect admin pages ? or create my own admin Middleware (not group) with auth()->check() and make some stuff like is_user_active and ....

also the web middlewareGroups : in laravel doc. ( the web middleware group is automatically applied to your routes/web.php file by the RouteServiceProvider. ) this means that we don't need to add ['web'] in route::group or we must put it in front routes and admin routes . Thanks

Please sign in or create an account to participate in this conversation.