1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 19:34:02 +00:00

Update README.md

This commit is contained in:
Samuel Štancl 2021-11-16 21:57:09 +01:00 committed by GitHub
parent b57b9837a0
commit 0a1552b1f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -498,9 +498,9 @@ $money->is($bar); // true
## Tips
### 💡 Accepted currency formats
### 💡 Accepted currency code formats
Most methods which accept a currency accept it in any format:
Most methods which accept a currency accept it in any of these formats:
```php
currency(USD::class);
currency(new USD);
@ -511,6 +511,20 @@ money(1000, 'USD')->convertTo(new CZK);
money(1000, new USD)->convertTo(CZK::class);
```
### 💡 Dynamically add currencies
Class currencies are elegant, but not necessary. If your currency specs come from the database, or some API, you can register them as arrays.
```php
// LoadCurrencies middleware
currencies()->add(cache()->remember('currencies', 3600, function () {
return UserCurrencies::where('user_id', auth()->id())->get()->toArray();
});
```
Where the DB call returns an array of array currencies following the [format mentioned above](#creating-a-currency).
## Development & contributing
Run all checks locally: