From f91b31717d09d9a41dc8eca840a191589656cc1d Mon Sep 17 00:00:00 2001 From: Rick Goemans Date: Wed, 20 Jan 2021 18:08:47 +0100 Subject: [PATCH] Added after column support for blueprint macros and prevented duplicated code --- src/Macros/Blueprint.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/Macros/Blueprint.php b/src/Macros/Blueprint.php index 8d5f3f7..e2af624 100644 --- a/src/Macros/Blueprint.php +++ b/src/Macros/Blueprint.php @@ -11,7 +11,7 @@ class Blueprint { public function encrypted(): Closure { - return function (string $name, ?array $indexes = null): void { + return function (string $name, ?array $indexes = null, ?string $after = null, bool $nullable = false): void { $columns = empty($indexes) ? [ $name, @@ -23,7 +23,13 @@ class Blueprint ); foreach ($columns as $column) { - $this->string($column); + $addedColumn = $this->string($column)->nullable($nullable); + + if($after) { + $addedColumn->after($after); + + $after = $column; + } } $this->index($columns); @@ -32,22 +38,8 @@ class Blueprint public function nullableEncrypted(): Closure { - return function (string $name, ?array $indexes = null): void { - $columns = empty($indexes) - ? [ - $name, - "{$name}_index", - ] - : array_merge( - [$name], - $indexes - ); - - foreach ($columns as $column) { - $this->string($column)->nullable(); - } - - $this->index($columns); + return function (string $name, ?array $indexes = null, ?string $after = null): void { + $this->encrypted($name, $indexes, $after, true); }; } }