您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CurrencyFactory.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Models\Setting\Currency;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Currency>
  7. */
  8. class CurrencyFactory extends Factory
  9. {
  10. /**
  11. * The name of the factory's corresponding model.
  12. */
  13. protected $model = Currency::class;
  14. /**
  15. * Define the model's default state.
  16. *
  17. * @return array<string, mixed>
  18. */
  19. public function definition(): array
  20. {
  21. $defaultCurrency = currency('USD');
  22. return [
  23. 'name' => $defaultCurrency->getName(),
  24. 'code' => $defaultCurrency->getCurrency(),
  25. 'rate' => $defaultCurrency->getRate(),
  26. 'precision' => $defaultCurrency->getPrecision(),
  27. 'symbol' => $defaultCurrency->getSymbol(),
  28. 'symbol_first' => $defaultCurrency->isSymbolFirst(),
  29. 'decimal_mark' => $defaultCurrency->getDecimalMark(),
  30. 'thousands_separator' => $defaultCurrency->getThousandsSeparator(),
  31. 'enabled' => true,
  32. ];
  33. }
  34. /**
  35. * Define a state for a specific currency.
  36. */
  37. public function forCurrency(string $code): Factory
  38. {
  39. $currency = currency($code);
  40. return $this->state([
  41. 'name' => $currency->getName(),
  42. 'code' => $currency->getCurrency(),
  43. 'rate' => $currency->getRate(),
  44. 'precision' => $currency->getPrecision(),
  45. 'symbol' => $currency->getSymbol(),
  46. 'symbol_first' => $currency->isSymbolFirst(),
  47. 'decimal_mark' => $currency->getDecimalMark(),
  48. 'thousands_separator' => $currency->getThousandsSeparator(),
  49. 'enabled' => true,
  50. ]);
  51. }
  52. }