Can't authenticate user in laravel

北城余情 提交于 2019-12-03 13:42:32
TonyArra

It sounds like from your error that your User model does not implement UserInterface (the default User Model that comes with Laravel does this properly, so I'm guessing you made a custom one)

http://github.com/laravel/laravel/blob/master/app/models/User.php

Make sure that the User model looks like this:

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {


/**
 * Get the unique identifier for the user.
 *
 * @return mixed
 */
public function getAuthIdentifier()
{
    return $this->getKey();
}

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->password;
}

/**
 * Get the e-mail address where password reminders are sent.
 *
 * @return string
 */
public function getReminderEmail()
{
    return $this->email;
}

// Add your other methods here

}

You don't show what userdata is defined as, but from the error message it seems like it's an instance of your User model class.

The Auth::attempt() method is looking for an array of the credentials not a model.

This error might also appear when you use a different model for users (example :member) if it's the case you need to update Authentication Model and Authentication Table in app/config/auth.php with the appropriate model / database table.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!