Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

JournalEntryCast.php 804B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Casts;
  3. use App\Utilities\Currency\CurrencyAccessor;
  4. use App\Utilities\Currency\CurrencyConverter;
  5. use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
  6. use Illuminate\Database\Eloquent\Model;
  7. use UnexpectedValueException;
  8. class JournalEntryCast implements CastsAttributes
  9. {
  10. public function get(Model $model, string $key, mixed $value, array $attributes): string
  11. {
  12. $currency_code = CurrencyAccessor::getDefaultCurrency();
  13. if ($value !== null) {
  14. return CurrencyConverter::prepareForMutator($value, $currency_code);
  15. }
  16. return '';
  17. }
  18. /**
  19. * @throws UnexpectedValueException
  20. */
  21. public function set(Model $model, string $key, mixed $value, array $attributes): int
  22. {
  23. return (int) $value;
  24. }
  25. }