2014-07-23 1 views
0

안녕하세요 저는 laravel을 (를) 처음 사용하고 있습니다. 이제 응용 프로그램의 인증을 시도하고 있습니다. 나는 이메일 확인에 의해 활성 내 계정에 시도 할 때 문제는 지금 내가 가지고 그것이 말하는 것입니다 :Laravel Timestamps ID에 대한 업데이트 오류

SQLSTATE [42S22] : 발견되지 칼럼 : 갱신 users : 'where 절'(SQL을 1054 알 수없는 열 '아이디' 나는 "idUser"라는 이름의 열이 내 데이터베이스에서 id가 null updated_at = 2014년 7월 23일 16시 51분 55초, code = active = 1)

을 설정합니다. 기본 열 "id"를 "idUser"로 어떻게 바꿀 수 있습니까?

컨트롤러의 코드입니다. idUser에 사용자 모델에서 http://laravel.com/docs/eloquent#basic-usage

// Model 
protected $primaryKey = 'whateverColumnYouHave'; 

답변

0

워드 프로세서를 읽어

보호 $ 기본 키 = 'idUser을';

참고 : Eloquent는 각 테이블에 id라는 기본 키 열이 있다고 가정합니다. primaryKey 속성을 정의하여이 규칙을 재정의 할 수 있습니다. 마찬가지로 모델을 사용할 때 사용해야하는 데이터베이스 연결의 이름을 재정의하기 위해 연결 속성을 정의 할 수 있습니다.

소스 : http://laravel.com/docs/eloquent#basic-usage

0

세트 $의 기본 키 :

/* 
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. '); 
} 
0

이 모델을 열고이 보호 변수를 추가합니다. 이렇게하면 기존 파일을 덮어 씁니다.

보호 된 $ 기본 키 = 'idUser'; // 기본 기본 키가 변경됩니다.

예 :

응용 프로그램/모델/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(); 
    } 

}