Laravel身份验证出错

时间:2014-12-17 17:48:34

标签: authentication laravel

我是Laravel的新手,我正在尝试在我的应用程序中实现身份验证,当我发布登录表单时,我的浏览器会返回此错误:

enter image description here

我不知道这个错误的含义,发生的位置或解决方法。

这是我的身份验证控制器中的登录功能,可以处理所有登录:

public function signin()
    {
        // validate the info, create rules for the inputs
        $rules = array(
            'email'    => 'required|email', // make sure the email is an actual email
            'password' => 'required|min:6' // password can only be alphanumeric and has to be greater than 3 characters
        );

        // run the validation rules on the inputs from the form
        $validator = Validator::make(Input::all(), $rules);

        // if the validator fails, redirect back to the form
        if ($validator->fails()) {
            return Redirect::to('/authentication')
                ->withErrors($validator) // send back all errors to the login form
                ->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
        } else {

            // create our user data for the authentication
            $user = array(
                'email'     => Input::get('email'),
                'password'  => Input::get('password')
            );

            // attempt to do the login
            if (Auth::attempt($user)) {

                // validation successful!
                // redirect them to the secure section or whatever
                // return Redirect::to('secure');
                // for now we'll just echo success (even though echoing in a controller is bad)
                return Redirect::to('dashboard.index');

            } else {

                // validation not successful, send back to form
                return Redirect::to('/authentication')
                    ->with('failed', 'Incorrect email / password!');

            }

        }
    }

这是我的用户模型:

<?php

class User extends Eloquent{

    // MASS ASSIGNMENT -------------------------------------------------------
    // define which attributes are mass assignable (for security)
    protected $fillable = array('email','school_id','role_id','activation_key','reset_key','login_status','account_status');

    // LINK THIS MODEL TO OUR DATABASE TABLE ---------------------------------
    protected $table = 'users';

    // DEFINE RELATIONSHIPS --------------------------------------------------
    public function roles() {
        return $this->belongsTo('Role');
    }

    public function schools() {
        return $this->belongsTo('Institution');
    }

    public function lectures() {
        return $this->hasOne('Lecturer');
    }

    public function students() {
        return $this->hasOne('Student');
    }

    public function getId()
    {
        return $this->id;
    }
}

1 个答案:

答案 0 :(得分:1)

让我们来看看Laravel的默认User模型:

class User extends Eloquent ...

到目前为止一切顺利

... implements UserInterface, RemindableInterface {

Oooops看起来像你错过了一些东西;)

这两个特征也并非不重要。

以下应该的样子:

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    // MASS ASSIGNMENT -------------------------------------------------------
    // define which attributes are mass assignable (for security)
    protected $fillable = array('email','school_id','role_id','activation_key','reset_key','login_status','account_status');

    // [the rest of your model]