我的用户表结构如下所示,我无法验证我的登录表单。请让我知道什么应该改变在总体的拉拉配置文件?当使用dd(Auth::$user)时,我得到的结果是“布尔假”;
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();
}
}//这是我的模型
<?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“作为我的其他字段。
注:登记簿对我来说很好。
发布于 2014-02-08 18:22:02
编辑:伍普斯刚刚意识到你一定已经解决了这个问题
$table->increments('userId');您使用userId作为主键而不是ID,但是雄辩的模型没有意识到这一点。您需要在用户模型中添加以下行:
protected $primaryKey = 'userId'; //this variable is defaulted to 'id'还应修改以下内容:
public function getAuthPassword() {
return $this->password;
}您没有使用“密码”作为您的密码列。改为:
public function getAuthPassword() {
return $this->userPassword;
}用户模型中的自动生成代码假定您使用默认字段名拉勒维尔,因此您需要确保用户模型和auth匹配您对表所做的更改。
https://stackoverflow.com/questions/21515063
复制相似问题