This commit is contained in:
Adrian Hopek
2022-04-08 12:42:24 +02:00
parent 4af0482a93
commit 6506855bba
50 changed files with 581 additions and 196 deletions

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Eloquent\Models\Profile;
use Toby\Eloquent\Models\User;
class ProfileFactory extends Factory
{
protected $model = Profile::class;
public function definition(): array
{
return [
"user_id" => User::factory(),
"first_name" => $this->faker->firstName(),
"last_name" => $this->faker->lastName(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"position" => $this->faker->jobTitle(),
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
];
}
}

View File

@@ -5,10 +5,9 @@ declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role;
use Toby\Eloquent\Models\Profile;
use Toby\Eloquent\Models\User;
class UserFactory extends Factory
@@ -18,17 +17,21 @@ class UserFactory extends Factory
public function definition(): array
{
return [
"first_name" => $this->faker->firstName(),
"last_name" => $this->faker->lastName(),
"email" => $this->faker->unique()->safeEmail(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"position" => $this->faker->jobTitle(),
"role" => Role::Employee,
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
"remember_token" => Str::random(10),
];
}
public function configure(): self
{
return $this->afterCreating(function (User $user): void {
if (!$user->profile()->exists()) {
Profile::factory()->for($user)->create();
}
});
}
public function admin(): static
{
return $this->state([