Skip to content

Instantly share code, notes, and snippets.

@lagbox
Last active January 6, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lagbox/0321f5ad7b6d9b29c60e to your computer and use it in GitHub Desktop.
Save lagbox/0321f5ad7b6d9b29c60e to your computer and use it in GitHub Desktop.
Just use your own schema builder
<?php
namespace App;
use Closure;
use Illuminate\Database\Schema\Builder;
class SchemaBuilder extends Builder
{
public function create($table, Closure $callback)
{
$required = ['created_at', 'updated_at', 'deleted_at'];
$blueprint = $this->createBlueprint($table);
$blueprint->create();
$callback($blueprint);
$diff = array_diff($required, array_pluck($blueprint->getColumns(), 'name'));
foreach ($diff as $missing) {
$blueprint->timestamp($missing)->nullable();
}
$this->build($blueprint);
}
}
<?php
$sb = app('App\SchemaBuilder');
$sb->create('testit', function (Blueprint $table) {
});
////////
artisan migrate --pretend
SomeRandomMigration: create table "testit" ("created_at" datetime null, "updated_at" datetime null, "deleted_at" datetime null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment