diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 091be54f5..332285ec5 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; use Laravel\Passport\Client; +use Laravel\Passport\Passport; class ClientFactory extends Factory { @@ -22,7 +23,7 @@ class ClientFactory extends Factory */ public function definition() { - return [ + return $this->ensurePrimaryKeyIsSet([ 'user_id' => null, 'name' => $this->faker->company, 'secret' => Str::random(40), @@ -30,7 +31,24 @@ public function definition() 'personal_access_client' => false, 'password_client' => false, 'revoked' => false, - ]; + ]); + } + + /** + * Ensure the primary key is set on the model when using UUIDs. + * + * @param array $data + * @return array + */ + protected function ensurePrimaryKeyIsSet(array $data) + { + if (Passport::clientUuids()) { + $keyName = (new $this->model)->getKeyName(); + + $data[$keyName] = (string) Str::orderedUuid(); + } + + return $data; } /**