Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
chore(model): fix relevancy while using Personnel::factory()
Browse files Browse the repository at this point in the history
In this case is when having relation with `User` model

Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Oct 14, 2023
1 parent 6c26827 commit b28b39b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/Models/Concerns/Factories/AsPersonnel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ trait AsPersonnel
{
public function withProfile(Enums\Gender $gender = null): static
{
return $this->has(Profile::factory(), 'profile')->state(fn () => [
'name' => $this->faker->firstName($gender?->toFaker()),
$gender = $gender ?: \fake()->randomElement(Enums\Gender::cases());

return $this->has(Profile::factory(), 'profile')->state(fn ($_, $user) => [
'name' => \fake()->firstName($gender->toFaker()),
'alias' => $user->name,
'email' => $user->email,
'gender' => $gender,
]);
}

Expand All @@ -26,13 +31,13 @@ public function withCompany(
false|DateTimeInterface $startDate = null,
): static {
if ($startDate === null) {
$startDate = $this->faker->dateTime();
$startDate = \fake()->dateTime();
}

return $this->hasAttached(Business::factory(), [
'is_primary' => $primary,
'type' => $type ?? $this->faker->randomElement(Enums\EmploymentType::cases()),
'status' => $status ?? $this->faker->randomElement(Enums\EmploymentStatus::cases()),
'type' => $type ?? \fake()->randomElement(Enums\EmploymentType::cases()),
'status' => $status ?? \fake()->randomElement(Enums\EmploymentStatus::cases()),
'start_date' => $startDate?->format('Y-m-d'),
'finish_date' => null,
], 'employers');
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Concerns/Factories/WithFileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait WithFileUpload
public function withFileUpload(FileUploadType $type = null): static
{
return $this->hasAttached(FileUpload::factory(), [
'type' => $type ?? $this->faker->randomElement(FileUploadType::cases()),
'type' => $type ?? \fake()->randomElement(FileUploadType::cases()),
], 'files');
}
}

0 comments on commit b28b39b

Please sign in to comment.