Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Ensure client model factory always creates models with a primary key, even when events are disabled #1492

Merged
merged 2 commits into from
Oct 15, 2021
Merged
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
22 changes: 20 additions & 2 deletions database/factories/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -22,15 +23,32 @@ class ClientFactory extends Factory
*/
public function definition()
{
return [
return $this->ensurePrimaryKeyIsSet([
'user_id' => null,
'name' => $this->faker->company,
'secret' => Str::random(40),
'redirect' => $this->faker->url,
'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;
}

/**
Expand Down