gpt4 book ai didi

Laravel 身份验证令人困惑

转载 作者:行者123 更新时间:2023-12-04 00:11:00 25 4
gpt4 key购买 nike

我是 Laravel 的初学者。

我想使用:

Auth::login(users::find(1))

结果:输入错误:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\users given

更改了模型以扩展 Authenticatable 而不是 Model。此外,我将 Auth 语句更改为:

Auth::login(users::where('id', 1))

结果:输入错误:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Database\Eloquent\Builder given

不知道你是否愿意帮助我,'感谢'

最佳答案

你应该在用户模型类中实现 Illuminate\Contracts\Auth\Authenticatable 以通过 Auth::login

Authenticate A User Instance

If you need to log an existing user instance into your application, you may call the login method with the user instance. The given object must be an implementation of the Illuminate\Contracts\Auth\Authenticatable contract. Of course, the App\User model included with Laravel already implements this interface:

Auth::login($user);

https://laravel.com/docs/5.1/authentication

或者你可以简单地这样做:

Auth::loginUsingId(1);

关于Laravel 身份验证令人困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35604385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com