Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LocalizationFactory.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\DateFormat;
  4. use App\Enums\NumberFormat;
  5. use App\Enums\TimeFormat;
  6. use App\Enums\WeekStart;
  7. use App\Models\Setting\Localization;
  8. use Illuminate\Database\Eloquent\Factories\Factory;
  9. /**
  10. * @extends Factory<Localization>
  11. */
  12. class LocalizationFactory extends Factory
  13. {
  14. /**
  15. * The name of the factory's corresponding model.
  16. */
  17. protected $model = Localization::class;
  18. /**
  19. * Define the model's default state.
  20. *
  21. * @return array<string, mixed>
  22. */
  23. public function definition(): array
  24. {
  25. return [
  26. 'date_format' => DateFormat::DEFAULT,
  27. 'time_format' => TimeFormat::DEFAULT,
  28. ];
  29. }
  30. public function withCountry(string $code, string $language = 'en'): Factory
  31. {
  32. $number_format = NumberFormat::fromLanguageAndCountry($language, $code) ?? NumberFormat::DEFAULT;
  33. $percent_first = Localization::isPercentFirst($language, $code) ?? false;
  34. $locale = Localization::getLocale($language, $code);
  35. $timezone = $this->faker->timezone($code);
  36. $week_start = Localization::getWeekStart($locale) ?? WeekStart::DEFAULT;
  37. return $this->state([
  38. 'language' => $language,
  39. 'timezone' => $timezone,
  40. 'number_format' => $number_format,
  41. 'percent_first' => $percent_first,
  42. 'week_start' => $week_start,
  43. 'fiscal_year_end_month' => 12,
  44. 'fiscal_year_end_day' => 31,
  45. ]);
  46. }
  47. }