2014-04-10 2 views
0

laravel 4 내 데이터베이스에 '활성'열을 추가하여 사용자가 활성화되어 있고 일시 중지되지 않았는지 확인하려고합니다. 여기에 내 마이그레이션 사용자 테이블이 있습니다.laravel 사용자가 활성 상태인지 확인 하시겠습니까?

public function up() 
{ 
    // 
    Schema::create(
     'users', 
     function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('email', 300); 
      $table->string('password', 60); 
      $table->boolean('active'); // check this one 
      $table->string('first_name', 100); 
      $table->string('last_name', 100); 
      $table->string('address', 250)->nullable(); 
      $table->string('city', 100)->nullable(); 
      $table->string('state', 2)->nullable(); 
      $table->string('zip', 5)->nullable(); 
      $table->string('phone', 10)->nullable(); 
      $table->timestamps(); 
     } 
    ); 
} 

/** 
* Reverse the migrations. 
* 
* @return void 
*/ 
public function down() 
{ 
    // 
    Schema::drop('users'); 
} 

$ table-> boolean ('active')를 사용하면 도움이 될 수 있습니까? // 이것을 확인하십시오

* 이것이 올바른 방법입니까? 그래서 나는 Auth 클래스를 사용하여 사용자가 활성화되어 있는지 확인합니다. Laravel\Docs\Authentication

그냥 내 2 비트 : 방법 구축

if (Auth::attempt(array('email' => $email, 'password' => $password, 'active' => 1))) 
{ 
    // The user is active, not suspended, and exists. 
} 

읽기 *

$is_active = Auth::user()->active; 

if (!$is_active == 1) 
    { 
echo "Account not activated"; 
    } 
+0

'활성화'대신 '활성'으로 지정하는 것 외에는 괜찮습니다. 사용자가 활성화되어 있지 않다는 것을 알려주는 필드를 추가하려는 경우 (읽기 또는 쓰기가 더 쉽습니다). –

+0

그러나 laravel이 '활성'또는 '활성화 됨'을 읽는 방법 또는 laravel이 알 수있는 중요하지 않은 방법은 무엇입니까? – user3150060

+0

또는 다음을 확인하기 위해 '활성화'한 경우 : Auth :: user() -> activated; ? – user3150060

답변

1

당신은 당신이 언급 한 방법 만이 존재 할 수있는 Laravel 방법을 수행 할 수 있습니다 당신은 데이터베이스가 권고되지 않습니다. 사용자 로그인 정보 (email, password & active)를 테이블에 별도의 user_profile 테이블에 보관해야합니다. 나중에 eloquent to map relations을 사용할 수 있습니다.

+0

로그인 정보와 프로필 정보를 다른 테이블로 구분할 때 어떤 이점이 있습니까? – jeteon

+2

린 쿼리의 인증 테이블을 사용하면 쿼리가 빨라집니다. 그런 다음 원하는 열로 user_profile 테이블을 확장 할 수 있습니다. – ultimate

관련 문제