我正在尝试在laravel应用程序中实现无密码的登录,但它显示错误:Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, string given
我正在使用的代码是:
$checkUser = 'manish.arora4926@gmail.com';
Auth::login($checkUser, true);
请帮我解决此问题。
答案 0 :(得分:3)
考虑到您的电子邮件列名称为email
,请尝试
$user = User::whereEmail('manish.arora4926@gmail.com')->first();
Auth::login($user)
或
Auth::loginUsingId($user->id);
答案 1 :(得分:1)
如果需要将现有用户实例记录到应用程序中,可以使用用户实例调用login方法。给定对象必须是Illuminate \ Contracts \ Auth \ Authenticatable合同的实现。当然,Laravel附带的App \ User模型已经实现了这个界面:
$ checkUser必须是雄辩的实例。所以你需要在验证用户之前访问eloquent
$checkUser=App\User::where('email','manish.arora4926@gmail.com')->first();
Auth::login($checkUser, true);
如果您只使用使用id
的登录知道用户的IDAuth::loginUsingId(1);
// Login and "remember" the given user...
Auth::loginUsingId(1, true);