refactor(factory): membuat state

This commit is contained in:
Yoga Pangestu 2025-12-03 20:38:48 +07:00
parent ebf6cd78ea
commit 8d70869766
2 changed files with 63 additions and 3 deletions

View File

@ -20,12 +20,55 @@ public function definition(): array
fake()->numerify('0812 #### #####'),
]),
'base_salary' => $this->faker->randomNumber(6),
'gender' => $this->faker->randomElement(Gender::cases()),
'address' => $this->faker->address(),
'birthdate' => $this->faker->dateTimeBetween('-60 years', '-18 years')->format('Y-m-d'),
'hire_date' => $this->faker->date(),
'resign_date' => $this->faker->optional()->date(),
'status' => $this->faker->randomElement(EmploymentStatus::cases()),
];
}
public function male(): Factory
{
return $this->state(function (array $attributes) {
return [
'gender' => Gender::MALE,
];
});
}
public function female(): Factory
{
return $this->state(function (array $attributes) {
return [
'gender' => Gender::FEMALE,
];
});
}
public function permanent(): Factory
{
return $this->state(function (array $attributes) {
return [
'status' => EmploymentStatus::PERMANENT,
];
});
}
public function contract(): Factory
{
return $this->state(function (array $attributes) {
return [
'status' => EmploymentStatus::CONTRACT,
];
});
}
public function intern(): Factory
{
return $this->state(function (array $attributes) {
return [
'status' => EmploymentStatus::INTERN,
];
});
}
}

View File

@ -14,7 +14,24 @@ public function definition(): array
'email' => $this->faker->unique()->safeEmail(),
'username' => fake()->unique()->regexify('[A-Za-z0-9]{8}'),
'password' => Hash::make(config('myconfig.password_default')),
'status' => $this->faker->randomElement(UserStatus::cases()),
];
}
public function active(): Factory
{
return $this->state(function (array $attributes) {
return [
'status' => UserStatus::ACTIVE,
];
});
}
public function inactive(): Factory
{
return $this->state(function (array $attributes) {
return [
'status' => UserStatus::INACTIVE,
];
});
}
}