Merge pull request #4 from kaiser-software/feature/add-after-support-for-blueprint-macros

Added after column support for blueprint macro
This commit is contained in:
Bjorn Voesten 2021-01-22 01:09:21 +01:00 committed by GitHub
commit 921f1df2ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 18 deletions

View File

@ -11,7 +11,7 @@ class Blueprint
{ {
public function encrypted(): Closure 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) $columns = empty($indexes)
? [ ? [
$name, $name,
@ -23,7 +23,13 @@ class Blueprint
); );
foreach ($columns as $column) { foreach ($columns as $column) {
$this->string($column); $addedColumn = $this->string($column)->nullable($nullable);
if($after) {
$addedColumn->after($after);
$after = $column;
}
} }
$this->index($columns); $this->index($columns);
@ -32,22 +38,8 @@ class Blueprint
public function nullableEncrypted(): Closure public function nullableEncrypted(): Closure
{ {
return function (string $name, ?array $indexes = null): void { return function (string $name, ?array $indexes = null, ?string $after = null): void {
$columns = empty($indexes) $this->encrypted($name, $indexes, $after, true);
? [
$name,
"{$name}_index",
]
: array_merge(
[$name],
$indexes
);
foreach ($columns as $column) {
$this->string($column)->nullable();
}
$this->index($columns);
}; };
} }
} }