Skip to content

Instantly share code, notes, and snippets.

@silentworks
Created July 10, 2017 23:58
Show Gist options
  • Save silentworks/e02d8e767e3243fccd14538177c3bd61 to your computer and use it in GitHub Desktop.
Save silentworks/e02d8e767e3243fccd14538177c3bd61 to your computer and use it in GitHub Desktop.
Using PHPmig migrations with Eloquent schema builder
<?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