-
-
Save lagbox/0321f5ad7b6d9b29c60e to your computer and use it in GitHub Desktop.
Just use your own schema builder
This file contains 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 | |
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); | |
} | |
} |
This file contains 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 | |
$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