有点疑问,也是分享,希望大家进来讨论一下,关于使用 Auth::attempt ($credentials) 验证报错的问题!
我使用 Auth::attempt ($credentials) 掩着那个登录时 ,当我的 User 模型为下面这种写法时,
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
}
在点击登录提交数据后会报 以下
Type error: Argument 1 passed to EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\User given, called in /home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 379
这样的错误!
当我将 User 模型文件修改成以下,这样就能够正常登录并跳转到个人页面
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
}
那么继承 Model 和 继承 Authenticatable 有什么区别呢,继承 Authenticatable 的作用是什么呢?为什么继承 Model 会报错呢?现在问题已经解决但是还是不清楚!
推荐文章: