From 28a554f4f5a2dcf0187249622aff3a028e07ed26 Mon Sep 17 00:00:00 2001 From: Choraimy Kroonstuiver <3661474+axlon@users.noreply.github.com> Date: Fri, 15 Oct 2021 13:00:18 +0200 Subject: [PATCH 1/2] Ensure client model factory always creates models with a primary key, even when events are disabled --- database/factories/ClientFactory.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 091be54f5..28d0bc457 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,23 @@ 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; } /** From 301c9d6c5a9a15fc20987f0b3eafd4dae84bc90b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 15 Oct 2021 09:27:55 -0500 Subject: [PATCH 2/2] Update ClientFactory.php --- database/factories/ClientFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 28d0bc457..332285ec5 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -44,6 +44,7 @@ protected function ensurePrimaryKeyIsSet(array $data) { if (Passport::clientUuids()) { $keyName = (new $this->model)->getKeyName(); + $data[$keyName] = (string) Str::orderedUuid(); }