laravel-4 - 无法在 Laravel 中对用户进行身份验证

标签 laravel-4 basic-authentication

        $userdata = array(
            'email' => Input::get('email'),
            'password'  => Input::get('password')
            );



        if (Auth::attempt($userdata)) {

            echo 'SUCCESS!';

        } else {        

            return Redirect::to('login');

        }

当我从浏览器运行应用程序时,出现此错误:
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Auth\UserInterface, instance of User given, called in /home/srtpl17/Sites/yatin.sr/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 316 and defined
我做错了什么?

最佳答案

听起来你的错误是你的用户模型没有实现 UserInterface (Laravel 附带的默认用户模型正确地做到了这一点,所以我猜你做了一个自定义的)

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

确保 User 模型如下所示:

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

}

关于laravel-4 - 无法在 Laravel 中对用户进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21723419/

相关文章:

html - Laravel Blade 模板 View HTML::style 未在子文件夹中链接

http - Node.JS 中的基本 HTTP 身份验证?

php - Laravel 4 中的多种用户类型 - 登录问题

php - 取消设置 cookie Laravel 4

php - 如何在 rest api 中验证/检查基本身份验证 header

ios - Afnetworking 2 基本授权帖子

authentication - HTTP 基本身份验证和 OAuth 2.0 是否相同?

java - Angular 6 基本身份验证从客户端返回 401

laravel - 如何更改 Paginator 的页面名称?

javascript - 使用 AJAX 提交表单 laravel