Laravel two diffrent middleware authentication fro

2019-09-03 15:08发布

问题:

I have two seprate table for authentication. Following middleware pointing to different table:

$this->middleware('auth:admin'); // - admins 
$this->middleware('auth'); // - user

The solution i need :

  • I want authentication must be done with two diffrent table through only "$this->middleware('auth')" middleware
  • Through middleware "$this->middleware('auth')" I want to login both admin and user. Currently admin and user login from diffrent middleware I have shown above.

For this, in which file and where I need to change in my project folder?

回答1:

If you want to have both "guards" be checked you can just pass multiple guards to the auth middleware.

$this->middleware('auth:web,admin');

This will spin through the guards passed and if any of them produce a user it will set that guard as the default moving forward.