diff --git a/src/core/src/Database/Eloquent/Concerns/HasUlids.php b/src/core/src/Database/Eloquent/Concerns/HasUlids.php new file mode 100644 index 000000000..f7768fe50 --- /dev/null +++ b/src/core/src/Database/Eloquent/Concerns/HasUlids.php @@ -0,0 +1,62 @@ +uniqueIds() as $column) { + if (empty($model->{$column})) { + $this->{$column} = $this->newUniqueId(); + } + } + } + + /** + * Generate a new UUID for the model. + */ + public function newUniqueId(): string + { + return strtolower((string) Str::ulid()); + } + + /** + * Get the columns that should receive a unique identifier. + */ + public function uniqueIds(): array + { + return [$this->getKeyName()]; + } + + /** + * Get the auto-incrementing key type. + */ + public function getKeyType(): string + { + if (in_array($this->getKeyName(), $this->uniqueIds())) { + return 'string'; + } + + return $this->keyType; + } + + /** + * Get the value indicating whether the IDs are incrementing. + */ + public function getIncrementing(): bool + { + if (in_array($this->getKeyName(), $this->uniqueIds())) { + return false; + } + + return $this->incrementing; + } +} diff --git a/src/core/src/Database/Eloquent/Concerns/HasUuids.php b/src/core/src/Database/Eloquent/Concerns/HasUuids.php new file mode 100644 index 000000000..b4e499679 --- /dev/null +++ b/src/core/src/Database/Eloquent/Concerns/HasUuids.php @@ -0,0 +1,62 @@ +uniqueIds() as $column) { + if (empty($model->{$column})) { + $this->{$column} = $this->newUniqueId(); + } + } + } + + /** + * Generate a new UUID for the model. + */ + public function newUniqueId(): string + { + return (string) Str::orderedUuid(); + } + + /** + * Get the columns that should receive a unique identifier. + */ + public function uniqueIds(): array + { + return [$this->getKeyName()]; + } + + /** + * Get the auto-incrementing key type. + */ + public function getKeyType(): string + { + if (in_array($this->getKeyName(), $this->uniqueIds())) { + return 'string'; + } + + return $this->keyType; + } + + /** + * Get the value indicating whether the IDs are incrementing. + */ + public function getIncrementing(): bool + { + if (in_array($this->getKeyName(), $this->uniqueIds())) { + return false; + } + + return $this->incrementing; + } +} diff --git a/src/foundation/src/Application.php b/src/foundation/src/Application.php index 972088506..3147df81b 100644 --- a/src/foundation/src/Application.php +++ b/src/foundation/src/Application.php @@ -31,7 +31,7 @@ class Application extends Container implements ApplicationContract * * @var string */ - public const VERSION = '0.1.5'; + public const VERSION = '0.1.6'; /** * The base path for the Hypervel installation.