libra/database/factories/BlockedTimeFactory.php

89 lines
2.1 KiB
PHP

<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BlockedTime>
*/
class BlockedTimeFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'block_date' => fake()->dateTimeBetween('now', '+30 days'),
'start_time' => null,
'end_time' => null,
'reason' => fake()->optional()->sentence(),
];
}
/**
* Create a full day block (all-day event).
*/
public function allDay(): static
{
return $this->state(fn (array $attributes) => [
'start_time' => null,
'end_time' => null,
]);
}
/**
* Create a partial day block with specific times.
*/
public function timeRange(string $start = '09:00', string $end = '12:00'): static
{
return $this->state(fn (array $attributes) => [
'start_time' => $start,
'end_time' => $end,
]);
}
/**
* Create an upcoming blocked time.
*/
public function upcoming(): static
{
return $this->state(fn (array $attributes) => [
'block_date' => fake()->dateTimeBetween('tomorrow', '+30 days'),
]);
}
/**
* Create a past blocked time.
*/
public function past(): static
{
return $this->state(fn (array $attributes) => [
'block_date' => fake()->dateTimeBetween('-30 days', 'yesterday'),
]);
}
/**
* Create a blocked time for today.
*/
public function today(): static
{
return $this->state(fn (array $attributes) => [
'block_date' => today(),
]);
}
/**
* Create a blocked time with a specific reason.
*/
public function withReason(?string $reason = null): static
{
return $this->state(fn (array $attributes) => [
'reason' => $reason ?? fake()->sentence(),
]);
}
}