Laravel 带有 Cartalyst Sentinel 的护照

Laravel passport with Cartalyst Sentinel

我正在使用 laravel passport 和 sentinel 开发 API。我想将它与 VUE js 一起使用。但是我在 oauth/token 中遇到了问题。

当我点击 URL 时出现错误

Call to undefined method Illuminate\Database\Query\Builder::getAuthPassword()

我的用户模型代码是

namespace App;

use Cartalyst\Sentinel\Users\EloquentUser;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends EloquentUser
{
    use HasApiTokens, Notifiable;

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

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

    public function findForPassport($username) {
        return $this->where('email', $username)->first();
    }


    public function photo(){
        return $this->belongsTo('App\Photo');
    }
}

如果我使用 Class User extends Authenticatable 那么它会工作并得到

status: 200, statusText: "OK"

,但是如果我使用 EloquentUser 然后我得到错误

Call to undefined method Illuminate\Database\Query\Builder:: getAuthPassword()

如何解决这个问题?

答案在错误中。

调用未定义的方法 Illuminate\Database\Query\Builder::getAuthPassword()

所以我只是将 Authenticatable 特征作为 Use Authenticatable; 并在命名空间

use Illuminate\Auth\Authenticatable;

中导入 class