Added after column support for blueprint macros and prevented duplicated code

This commit is contained in:
Rick Goemans 2021-01-20 18:08:47 +01:00
parent 13bfb5e4ee
commit f91b31717d
1 changed files with 10 additions and 18 deletions

View File

@ -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);
};
}
}