Skip to content

Commit

Permalink
Default currency option when calling $user->creditCurrency method. (#5)
Browse files Browse the repository at this point in the history
Default currency option in config
  • Loading branch information
Luan1Schons authored Oct 15, 2024
1 parent c6f9b0b commit 43e19e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ return [
* Default table name.
* If you have changed the migration, make sure you change this too.
*/
'table' => 'balances'
'table' => 'balances',
'default_currency' => 'EUR', // Default Currency
];

```
Expand Down
3 changes: 2 additions & 1 deletion config/balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
* Default table name.
* If you have changed the migration, make sure you change this too.
*/
'table' => 'balances'
'table' => 'balances',
'default_currency' => 'USD', // Default currency
];
14 changes: 10 additions & 4 deletions src/Traits/HasBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

trait HasBalance
{
protected string $currency = 'USD';
protected string $currency;

public function __construct()
{
$this->currency = config('balance.default_currency', 'USD');
}

public function credits(): MorphMany
{
Expand All @@ -18,11 +23,12 @@ public function credits(): MorphMany

public function withCurrency(string $currency): self
{
$this->currency = $currency;
$clone = clone $this;
$clone->currency = $currency;

return $this;
return $clone;
}

protected function credit(): Attribute
{
return Attribute::make(
Expand Down

0 comments on commit 43e19e3

Please sign in to comment.