Skip to content

Commit

Permalink
Merge pull request #79 from bavix/relations
Browse files Browse the repository at this point in the history
#78 Relations
  • Loading branch information
rez1dent3 authored Aug 3, 2019
2 parents 2e43659 + 4913c76 commit 39de5d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.1.4] - 2019-08-03
### Added
- Add support `barryvdh/laravel-ide-helper`

### Fixed
- Fixed receiving `wallets.transfers` relationship @imhuso

## [3.1.3] - 2019-07-31
### Added
- Add support SQLite on command `RefreshBalance`
Expand Down Expand Up @@ -369,7 +376,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
- Exceptions: AmountInvalid, BalanceIsEmpty.
- Models: Transfer, Transaction.

[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.1.3...HEAD
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.1.4...HEAD
[3.1.4]: https://github.com/bavix/laravel-wallet/compare/3.1.3...3.1.4
[3.1.3]: https://github.com/bavix/laravel-wallet/compare/3.1.2...3.1.3
[3.1.2]: https://github.com/bavix/laravel-wallet/compare/3.1.1...3.1.2
[3.1.1]: https://github.com/bavix/laravel-wallet/compare/3.1.0...3.1.1
Expand Down
8 changes: 6 additions & 2 deletions src/Services/WalletService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ public function checkAmount(int $amount): void

/**
* @param Wallet $object
* @param bool $autoSave
* @return WalletModel
*/
public function getWallet(Wallet $object): WalletModel
public function getWallet(Wallet $object, bool $autoSave = true): WalletModel
{
/**
* @var WalletModel $wallet
Expand All @@ -84,7 +85,10 @@ public function getWallet(Wallet $object): WalletModel
$wallet = $object->wallet;
}

$wallet->exists or $wallet->save();
if ($autoSave) {
$wallet->exists or $wallet->save();
}

return $wallet;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function forceTransfer(Wallet $wallet, int $amount, ?array $meta = null):
public function transfers(): MorphMany
{
return app(WalletService::class)
->getWallet($this)
->getWallet($this, false)
->morphMany(config('wallet.transfer.model'), 'from');
}

Expand Down

0 comments on commit 39de5d3

Please sign in to comment.