Laravel 更新后的用户模型错误(类用户包含 3 个抽象方法)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23102033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:22:00  来源:igfitidea点击:

User model error after Laravel update (Class User contains 3 abstract method)

phplaravellaravel-4

提问by kjames

After I update my laravel using composer update, I got this

在我使用 composer update 更新我的 laravel 后,我得到了这个

"type":"Symfony\Component\Debug\Exception\FatalErrorException",
"message":"Class User contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Auth\UserInterface::setRememberToken, Illuminate\Auth\UserInterface::getRememberTokenName, Illuminate\Auth\Reminders\RemindableInterface::getReminderEmail)",
"file":"D:\app\models\User.php",
"line":54

error when authenticating.

验证时出错。

回答by majidarif

This error happened because of the latest commit.

由于最新的提交而发生此错误。

You can check the upgrade documentation here, to fix this issue.

您可以在此处查看升级文档以解决此问题。

As stated, add the following to your User.phpmodel class:

如上所述,将以下内容添加到您的User.php模型类中:

public function getRememberToken()
{
    return $this->remember_token;
}

public function setRememberToken($value)
{
    $this->remember_token = $value;
}

public function getRememberTokenName()
{
    return 'remember_token';
}

回答by General Omosco

This is what worked for me by adding the below to app/User

通过将以下内容添加到,这对我有用 app/User

 public function getJWTIdentifier()
    {
        return $this->getKey();
    }
    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

Example app/User

例子 app/User

 <?php

namespace App;

use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }
    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}