diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 96d62d6..774d55b 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -21,7 +21,7 @@ jobs: ref: ${{ github.head_ref }} - name: Laravel pint - uses: aglipanci/laravel-pint-action@2.3.0 + uses: aglipanci/laravel-pint-action@2.3.1 with: preset: laravel diff --git a/config/human-keys.php b/config/human-keys.php index 03d296e..d3bfd51 100644 --- a/config/human-keys.php +++ b/config/human-keys.php @@ -1,5 +1,7 @@ getKeyName(), $this->humanKeys(), true)) { - $this->keyType = 'string'; - $this->incrementing = false; - } - } - public static function bootHasHumanKey(): void { static::creating(static function (Model $model) { @@ -34,6 +26,23 @@ public static function bootHasHumanKey(): void }); } + public static function humanKeyPrefix(): string + { + return Str::of(static::class) + ->classBasename() + ->lower() + ->limit(3, '') + ->toString(); + } + + public function initializeHasHumanKey(): void + { + if (in_array($this->getKeyName(), $this->humanKeys(), true)) { + $this->keyType = 'string'; + $this->incrementing = false; + } + } + /** * Get the columns that should receive human-readable keys. */ @@ -46,13 +55,4 @@ public function newHumanKey(): string { return HumanKeys::generate(static::humanKeyPrefix()); } - - public static function humanKeyPrefix(): string - { - return Str::of(static::class) - ->classBasename() - ->lower() - ->limit(3, '') - ->toString(); - } } diff --git a/tests/Pest.php b/tests/Pest.php index 20fe91f..26fd523 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,7 @@ in(__DIR__);