关于id的Laravel时间戳更新错误

关于id的Laravel时间戳更新错误,laravel,timestamp,Laravel,Timestamp,嗨,我是新来的拉威尔,我现在正试图做我的应用程序的身份验证。 当我试图通过电子邮件检查激活我的帐户时,我现在遇到的问题是它说: SQLSTATE[42S22]:未找到列:在where子句中找到1054未知列“id”(SQL:updateuserssetupdate\u at=2014-07-23 16:51:55,code=,active=1,其中id为空) 在我的数据库中有一列名为“idUser”。如何将默认列“id”更改为“idUser” 这是我在控制器中的代码 /* Email Activ

嗨,我是新来的拉威尔,我现在正试图做我的应用程序的身份验证。 当我试图通过电子邮件检查激活我的帐户时,我现在遇到的问题是它说:

SQLSTATE[42S22]:未找到列:在where子句中找到1054未知列“id”(SQL:update
users
set
update\u at
=2014-07-23 16:51:55,
code
=,
active
=1,其中
id
为空)

在我的数据库中有一列名为“idUser”。如何将默认列“id”更改为“idUser”

这是我在控制器中的代码

/*
Email Activation
*/
public function getActivate($code){
     $user=User::where('code','=',$code)->where('active','=',0);
     if($user->count()){

        $user = $user->first();
        //Update user to active state
        $user->active   =1;
        $user->code     ='';
        if($user->save()){
           return Redirect::route('home')
           ->with('flash_message','Activated! You can now sign in!');
        }

     }
    return Redirect::route('home')
        ->with('flash_message','Could not activate your account.Please try again later. ');
}
阅读文档:


将用户模型中的$primaryKey设置为idUser:

受保护的$primaryKey='idUser'

注意:Eloquent还将假定每个表都有一个名为id的主键列。您可以定义一个primaryKey属性来覆盖此约定。同样,您可以定义一个连接属性来覆盖在使用模型时应该使用的数据库连接的名称


来源:

打开您的模型并添加此受保护的变量。这将覆盖现有的

受保护的$primaryKey='idUser'//这将更改默认主键

例:

app/models/user.php

class User extends Eloquent  {

    protected $table = 'userlists'; //This will change your default table

    protected $primaryKey = 'id'; //This will change the default primary key.

    protected $hidden = array('password'); 

    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

}
class User extends Eloquent  {

    protected $table = 'userlists'; //This will change your default table

    protected $primaryKey = 'id'; //This will change the default primary key.

    protected $hidden = array('password'); 

    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

}