This commit is contained in:
Adrian Hopek
2022-01-21 08:45:42 +01:00
parent 652587dbf1
commit a62a428781
12 changed files with 420 additions and 8 deletions

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Toby\Models\User;
use Toby\Models\YearPeriod;
class VacationLimitFactory extends Factory
{
public function definition(): array
{
$hasVacation = $this->faker->boolean(75);
return [
"user_id" => User::factory(),
"year_period_id" => YearPeriod::factory(),
"has_vacation" => $hasVacation,
"days" => $hasVacation ? $this->faker->numberBetween(20, 26) : null,
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Toby\Models\User;
use Toby\Models\YearPeriod;
return new class() extends Migration {
public function up(): void
{
Schema::create('vacation_limits', function (Blueprint $table): void {
$table->id();
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
$table->boolean("has_vacation")->default(false);
$table->integer("days")->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('vacation_limits');
}
};

View File

@@ -7,6 +7,7 @@ namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon;
use Toby\Models\User;
use Toby\Models\VacationLimit;
use Toby\Models\YearPeriod;
class DatabaseSeeder extends Seeder
@@ -18,11 +19,23 @@ class DatabaseSeeder extends Seeder
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
])->create();
YearPeriod::factory([
"year" => Carbon::now()->year,
])->create();
YearPeriod::factory([
"year" => Carbon::now()->year + 1,
])->create();
$users = User::all();
YearPeriod::factory()
->count(3)
->sequence(
["year" => Carbon::now()->year - 1],
["year" => Carbon::now()->year],
["year" => Carbon::now()->year + 1],
)
->afterCreating(function (YearPeriod $yearPeriod) use ($users) {
foreach ($users as $user) {
VacationLimit::factory()
->for($yearPeriod)
->for($user)
->create();
}
})
->create();
}
}