Skip to content

Instantly share code, notes, and snippets.

@kidino
Last active January 29, 2026 05:00
Show Gist options
  • Select an option

  • Save kidino/a42476a77245da28d04d527bb3c4c6e2 to your computer and use it in GitHub Desktop.

Select an option

Save kidino/a42476a77245da28d04d527bb3c4c6e2 to your computer and use it in GitHub Desktop.
leave factory
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\LeaveApplication>
*/
class LeaveApplicationFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$fromDate = fake()->dateTimeBetween('-30 days', '+30 days');
$toDate = fake()->dateTimeBetween($fromDate->format('Y-m-d'),
$fromDate->format('Y-m-d') . ' +14 days');
return [
'user_id' => \App\Models\User::inRandomOrder()->first()?->id ??
\App\Models\User::factory(),
'from_date' => $fromDate,
'to_date' => $toDate,
'leave_type' => fake()->randomElement(['annual','medical','compassionate','emergency']),
'status' => fake()->randomElement(['pending','approved','rejected','revoked']),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment