Created
July 10, 2017 23:58
-
-
Save silentworks/e02d8e767e3243fccd14538177c3bd61 to your computer and use it in GitHub Desktop.
Using PHPmig migrations with Eloquent schema builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Phpmig\Migration\Migration; | |
class CreateUsersTable extends Migration | |
{ | |
protected $tableName; | |
/* @var \Illuminate\Database\Schema\Builder $schema */ | |
protected $schema; | |
public function init() | |
{ | |
$this->tableName = 'users'; | |
$this->schema = $this->get('db')->schema(); | |
} | |
/** | |
* Do the migration | |
*/ | |
public function up() | |
{ | |
/* @var \Illuminate\Database\Schema\Blueprint $table */ | |
$this->schema->create($this->tableName, function ($table) | |
{ | |
$table->increments('id'); | |
$table->string('name'); | |
$table->integer('age'); | |
$table->dateTime('dob')->nullable(); | |
$table->integer('active')->default(0); | |
$table->integer('created_by'); | |
$table->integer('updated_by')->nullable(); | |
$table->timestamps(); | |
$table->softDeletes(); | |
}); | |
} | |
/** | |
* Undo the migration | |
*/ | |
public function down() | |
{ | |
$this->schema->drop($this->tableName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment