首页 文章

Laravel - 身份验证特征错误异常

提问于
浏览
1

我正在 Laravel 应用程序中进行ajax登录 . 它在我的本地环境中运行良好,但我将网站移至Production,登录后我看到了这个例外

User.php第29行中的ErrorException:Illuminate \ Foundation \ Auth \ User和Illuminate \ Auth \ Authenticatable在App \ User的组合中定义相同的属性($ rememberTokenName) . 这可能是不兼容的,为了提高可维护性,请考虑在特征中使用访问器方法 . 上课是由

我的用户模型是

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, \Illuminate\Auth\Authenticatable;

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

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

1 回答

  • 0

    Illuminate\Foundation\Auth\User 已经使用了 Illuminate\Contracts\Auth\Authenticatable ,所以你基本上应用了两次导致该错误的特征 .

    这是Illuminate \ Foundation \ Auth \ User.php的代码

    <?php
    
    namespace Illuminate\Foundation\Auth;
    
    use Illuminate\Auth\Authenticatable;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Auth\Passwords\CanResetPassword;
    use Illuminate\Foundation\Auth\Access\Authorizable;
    use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
    use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
    use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
    
    class User extends Model implements
        AuthenticatableContract,
        AuthorizableContract,
        CanResetPasswordContract
    {
        use Authenticatable, Authorizable, CanResetPassword;
    }
    

    另外一个侧面建议可能会将您的别名位 as Authenticable 重命名为 AuthUser / BaseUser 更明确的内容,因此很明显您正在扩展User类 .

相关问题