*/ class ShiftFactory extends Factory { protected $model = Shift::class; /** * @return array */ public function definition(): array { $code = fake()->randomElement(['A', 'B', 'C', 'Night']); $times = match ($code) { 'A' => ['starts_at' => '06:00:00', 'ends_at' => '14:00:00'], 'B' => ['starts_at' => '14:00:00', 'ends_at' => '22:00:00'], 'C' => ['starts_at' => '22:00:00', 'ends_at' => '06:00:00'], default => ['starts_at' => '22:00:00', 'ends_at' => '06:00:00'], }; return [ 'name' => match ($code) { 'A' => 'Morning Shift', 'B' => 'Afternoon Shift', 'C' => 'Evening Shift', default => 'Night Shift', }, 'code' => $code.'-'.fake()->unique()->numerify('###'), 'starts_at' => $times['starts_at'], 'ends_at' => $times['ends_at'], 'description' => fake()->optional()->sentence(), 'is_active' => true, ]; } public function shiftA(): static { return $this->state(fn (array $attributes): array => [ 'name' => 'Shift A', 'code' => 'A', 'starts_at' => '06:00:00', 'ends_at' => '14:00:00', ]); } public function shiftB(): static { return $this->state(fn (array $attributes): array => [ 'name' => 'Shift B', 'code' => 'B', 'starts_at' => '14:00:00', 'ends_at' => '22:00:00', ]); } public function shiftC(): static { return $this->state(fn (array $attributes): array => [ 'name' => 'Shift C', 'code' => 'C', 'starts_at' => '22:00:00', 'ends_at' => '06:00:00', ]); } public function night(): static { return $this->state(fn (array $attributes): array => [ 'name' => 'Night Shift', 'code' => 'Night', 'starts_at' => '22:00:00', 'ends_at' => '06:00:00', ]); } }