首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法验证laravel-4的登录

无法验证laravel-4的登录
EN

Stack Overflow用户
提问于 2014-02-02 19:22:25
回答 1查看 87关注 0票数 0

我的用户表结构如下所示,我无法验证我的登录表单。请让我知道什么应该改变在总体的拉拉配置文件?当使用dd(Auth::$user)时,我得到的结果是“布尔假”;

代码语言:javascript
复制
Schema::create('users', function($table){
$table->increments('userId');
$table->string('userName');
$table->string('userPassword');
$table->timestamps();
});

// My UserController function is as under
    public function postLogin() {
        $user = array(
            'userName' => Input::get('username'),
            'userPassword' => Input::get('password')
        );

        //dd(Auth::attempt($user));

        if( Auth::attempt($user) ) {
            return Redirect::to('/')->with('message', 'You are logged in');
        } else {
            return Redirect::route('login')
                ->with('message', 'Your username/password combination was incorrect')
                ->withInput();
        }
    }

//这是我的模型

代码语言:javascript
复制
<?php

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

class User extends BaseModel implements UserInterface, RemindableInterface {

    public static $rules = array(
        'username' => 'required|unique:users|alpha_dash|min:4',
        'password' => 'required|alpha_num|between:4,8|confirmed',
        'password_confirmation' => 'required|alpha_num|between:4,8'
    );

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('userPassword');

    /**
     * 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;
    }

}

第二,当我使用“$table->时间戳()”时,通过迁移获得"created_at,updated_at“,请建议我如何将"created_at,updated_at”命名为camel case "createdAt,updatedAt“作为我的其他字段。

注:登记簿对我来说很好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-08 18:22:02

编辑:伍普斯刚刚意识到你一定已经解决了这个问题

代码语言:javascript
复制
$table->increments('userId');

您使用userId作为主键而不是ID,但是雄辩的模型没有意识到这一点。您需要在用户模型中添加以下行:

代码语言:javascript
复制
protected $primaryKey = 'userId';  //this variable is defaulted to 'id'

还应修改以下内容:

代码语言:javascript
复制
public function getAuthPassword() {
    return $this->password;  
}

您没有使用“密码”作为您的密码列。改为:

代码语言:javascript
复制
public function getAuthPassword() {
    return $this->userPassword;  
}

用户模型中的自动生成代码假定您使用默认字段名拉勒维尔,因此您需要确保用户模型和auth匹配您对表所做的更改。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21515063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档