Skip to content

Instantly share code, notes, and snippets.

@clecidor
Last active August 29, 2015 14:16
Show Gist options
  • Save clecidor/1aa2e06a4ab1e721ea12 to your computer and use it in GitHub Desktop.
Save clecidor/1aa2e06a4ab1e721ea12 to your computer and use it in GitHub Desktop.
create_users_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
protected $table = User::TABLE;
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create($this->table, function($table)
{
$table->engine = 'InnoDB';
$table->increments(User::PRIMARY_KEY);
$table->string(User::USERNAME, 60)->unique();
$table->string(User::EMAIL)->unique();
$table->string(User::PASSWORD, 128);
$table->timestamps();
$table->timestamp(User::LOGIN)->nullable();
$table->boolean(User::STATUS)->default(0);
$table->string(User::INIT)->unique();
$table->string(User::TIMEZONE, 32)->nullable();
$table->string(User::LANGUAGE, 12)->nullable();
$table->binary(User::DATA)->nullable();
$table->rememberToken();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable($this->table))
{
Schema::drop($this->table);
}
}
}
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Reimy\Extensions\Html\UserFormTraits;
class User extends BaseModel implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait, UserFormTraits;
const TABLE = 'users';
const PRIMARY_KEY = 'id';
const USERNAME = 'username';
const EMAIL = 'email';
const EMAIL_CONF = 'email_conf';
const PASSWORD = 'password';
const PASSWORD_CONF = 'password_conf';
const LOGIN = 'login_at';
const STATUS = 'status';
const INIT = 'init_email';
const TIMEZONE = 'timezone';
const LANGUAGE = 'language';
const DATA = 'data';
const REMEMBER = 'remember_me';
protected $guarded = array(self::PRIMARY_KEY, self::PASSWORD);
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array(self::PASSWORD, 'remember_token');
public function profile() {
return $this->hasOne('UserProfile', UserProfile::FOREIGN_KEY);
}
}
@clecidor
Copy link
Author

clecidor commented Mar 9, 2015

Example of using constants to help IDE facilitate increased developer productivity, and to help catch typos/bugs at compile time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment