using laravel 4 I am trying to add 'active' column to my database to check if the user is active and is not suspended , here is my migration users table.
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');
}
could you help me if I use $table->boolean('active'); // check this one
*is this the right way to do it? so I can use the Auth class like this to check if the user is active or not? *
$is_active = Auth::user()->active;
if (!$is_active == 1)
{
echo "Account not activated";
}
You can do it the way you have mentioned but the Laravel way to do this exists
if (Auth::attempt(array('email' => $email, 'password' => $password, 'active' => 1)))
{
// The user is active, not suspended, and exists.
}
Read : Laravel\Docs\Authentication
Just my 2 bit : The way are building you database is not advised. You should keep your user login information (email
, password
& active
) in users
table and others in a separate user_profile
table. Later you can use eloquent to map relations.