|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Eclipse\World\Factories; |
| 4 | + |
| 5 | +use Eclipse\World\Models\Country; |
| 6 | +use Eclipse\World\Models\CountrySpecialRegion; |
| 7 | +use Eclipse\World\Models\Region; |
| 8 | +use Illuminate\Database\Eloquent\Factories\Factory; |
| 9 | + |
| 10 | +class CountrySpecialRegionFactory extends Factory |
| 11 | +{ |
| 12 | + /** |
| 13 | + * The name of the factory's corresponding model. |
| 14 | + * |
| 15 | + * @var string |
| 16 | + */ |
| 17 | + protected $model = CountrySpecialRegion::class; |
| 18 | + |
| 19 | + /** |
| 20 | + * Define the model's default state. |
| 21 | + * |
| 22 | + * @return array<string, mixed> |
| 23 | + */ |
| 24 | + public function definition(): array |
| 25 | + { |
| 26 | + return [ |
| 27 | + 'country_id' => Country::factory(), |
| 28 | + 'region_id' => Region::factory()->special(), |
| 29 | + 'start_date' => $this->faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'), |
| 30 | + 'end_date' => $this->faker->optional(0.3)->dateTimeBetween('now', '+2 years')?->format('Y-m-d'), |
| 31 | + ]; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Set the region as active. |
| 36 | + * |
| 37 | + * @return $this |
| 38 | + */ |
| 39 | + public function active(): static |
| 40 | + { |
| 41 | + return $this->state([ |
| 42 | + 'start_date' => $this->faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'), |
| 43 | + 'end_date' => null, |
| 44 | + ]); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Set the region as ended. |
| 49 | + * |
| 50 | + * @return $this |
| 51 | + */ |
| 52 | + public function ended(): static |
| 53 | + { |
| 54 | + return $this->state([ |
| 55 | + 'start_date' => $this->faker->dateTimeBetween('-2 years', '-6 months')->format('Y-m-d'), |
| 56 | + 'end_date' => $this->faker->dateTimeBetween('-6 months', 'now')->format('Y-m-d'), |
| 57 | + ]); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Set the region as future. |
| 62 | + * |
| 63 | + * @return $this |
| 64 | + */ |
| 65 | + public function future(): static |
| 66 | + { |
| 67 | + return $this->state([ |
| 68 | + 'start_date' => $this->faker->dateTimeBetween('now', '+6 months')->format('Y-m-d'), |
| 69 | + 'end_date' => $this->faker->optional(0.5)->dateTimeBetween('+6 months', '+2 years')?->format('Y-m-d'), |
| 70 | + ]); |
| 71 | + } |
| 72 | +} |
0 commit comments