
* change layout * change layout * #22 - wip * wip * wip * #22 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - added some tests * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - cr fixes * #22 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Toby\Domain\Enums\VacationRequestState;
|
|
use Toby\Domain\Enums\VacationType;
|
|
use Toby\Eloquent\Models\User;
|
|
use Toby\Eloquent\Models\VacationRequest;
|
|
use Toby\Eloquent\Models\YearPeriod;
|
|
|
|
class VacationRequestFactory extends Factory
|
|
{
|
|
protected $model = VacationRequest::class;
|
|
private static int $number = 1;
|
|
|
|
public function definition(): array
|
|
{
|
|
$from = CarbonImmutable::create($this->faker->dateTimeThisYear);
|
|
$days = $this->faker->numberBetween(0, 20);
|
|
|
|
return [
|
|
"user_id" => User::factory(),
|
|
"year_period_id" => YearPeriod::factory(),
|
|
"name" => fn(array $attributes) => $this->generateName($attributes),
|
|
"type" => $this->faker->randomElement(VacationType::cases()),
|
|
"state" => $this->faker->randomElement(VacationRequestState::cases()),
|
|
"from" => $from,
|
|
"to" => $from->addDays($days),
|
|
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
|
|
];
|
|
}
|
|
|
|
protected function generateName(array $attributes): string
|
|
{
|
|
$year = YearPeriod::find($attributes["year_period_id"])->year;
|
|
$number = static::$number++;
|
|
|
|
return "{$number}/{$year}";
|
|
}
|
|
}
|