Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ There is only one function for Blueprint `enumeration` to create a column in tab

```php
// Accepts PHP Enums and Strings
\Illuminate\Database\Schema\Blueprint::enumeration(string $name);
\Illuminate\Database\Schema\Blueprint::enumeration(string $name, string $type, ?array $options = null);

// For Enum List e.g: SomeEnum[]
\Illuminate\Database\Schema\Blueprint::enumerations(string $name, string $type, ?array $options = null);
```

### Full Migration Example
Expand All @@ -79,7 +82,8 @@ public function up(): void
Schema::createEnum(MyEnum::class);
Schema::create('users', function(Blueprint $table) {
$table->id();
$table->enumeration(MyEnum::class);
$table->enumeration('my_enum_field', MyEnum::class); // Single Enum field
$table->enumerations('my_list', MyEnum::class); // Array of Enums field
});
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"require": {
"php": ">=8.1",
"ext-pdo": "*",
"illuminate/database": "^9|^10|^11",
"illuminate/support": "^9|^10|^11"
"illuminate/database": "^9|^10|^11|^12",
"illuminate/support": "^9|^10|^11|^12"
},
"require-dev": {
"laravel/pint": "^1.15",
Expand Down
11 changes: 11 additions & 0 deletions src/Mixins/BlueprintExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public function enumeration(): Closure
]);
};
}

public function enumerations(): Closure
{
return function (string $name, string $type, array $options = []) {
/** @var $this Blueprint */
return $this->addColumn('enumerations', $name, [
'pg_enum' => $type,
...$options,
]);
};
}
}
10 changes: 10 additions & 0 deletions src/Mixins/GrammarExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ public function typeEnumeration(): Closure
};
};
}

public function typeEnumerations(): Closure
{
return function (ColumnDefinition $columnDefinition) {
return match (class_exists($name = $columnDefinition['pg_enum'])) {
true => Str::snake((new ReflectionEnum($name))->getShortName()) . '[]',
false => $name
};
};
}
}