如何在 laravel 护照中实现多身份验证
问题描述
我有两个用户 admin/user 我想验证这两个用户的 api,它适用于一个用户,但不适用于管理员
I have two users admin/user i want to authenticate this two users for api, it is working for one user but its not working for admin
看看我尝试了什么在管理控制器中
see what i have tried in admin controller
在 api.php 中
and in api.php
当我尝试为管理员调用尝试函数时,它给了我错误
When i try to call attempt function for admin its giving me error
BadMethodCallException方法 IlluminateAuthRequestGuard::attempt 不存在.
BadMethodCallException Method IlluminateAuthRequestGuard::attempt does not exist.
您能否分享您对如何在 laravel/passport 中进行多身份验证的想法
can you please share your ideas over how to do multiauth in laravel/passport
推荐答案
您可以在 laravel 护照中实现多身份验证,您必须按照以下步骤操作
you can implement multiauth in laravel passport you have to follow below steps
1) 在我创建的情况下创建 4 个警卫
1) create 4 guards in my situation i created like
然后在控制器中记录该类型的用户时,请确保您使用的是 sessio 驱动程序保护,例如
then when logging that type of user in controller make sure you are using sessio driver guards like
用户控制器.php
在 admincontroller.php 中
in admincontroller.php
并且在检查令牌时使用护照司机警卫,例如
and when checking the token use the passport driver guard like
在中间件中
这篇关于如何在 laravel 护照中实现多身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!