Skip to content

Commit 9c19662

Browse files
committed
add holder transfer's
1 parent 56ba90f commit 9c19662

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Traits/CanPay.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Bavix\Wallet\Exceptions\ProductEnded;
66
use Bavix\Wallet\Interfaces\Product;
77
use Bavix\Wallet\Models\Transfer;
8+
use Bavix\Wallet\Models\Wallet;
89
use Illuminate\Database\Eloquent\Model;
910
use Illuminate\Database\Eloquent\ModelNotFoundException;
1011
use Illuminate\Support\Facades\DB;
@@ -156,7 +157,7 @@ public function paid(Product $product, bool $gifts = false): ?Transfer
156157
* @var Model $product
157158
* @var Transfer $query
158159
*/
159-
$query = $this->transfers();
160+
$query = $this->holderTransfers();
160161
return $query
161162
->where('to_type', $product->getMorphClass())
162163
->where('to_id', $product->getKey())

src/Traits/HasWallet.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,20 @@ public function forceTransfer(Wallet $wallet, int $amount, ?array $meta = null,
296296
});
297297
}
298298

299+
/**
300+
* holder transfers
301+
*
302+
* @return MorphMany
303+
*/
304+
public function holderTransfers(): MorphMany
305+
{
306+
if ($this instanceof WalletModel) {
307+
return $this->holder->transfers();
308+
}
309+
310+
return $this->transfers();
311+
}
312+
299313
/**
300314
* the transfer table is used to confirm the payment
301315
* this method receives all transfers
@@ -304,8 +318,7 @@ public function forceTransfer(Wallet $wallet, int $amount, ?array $meta = null,
304318
*/
305319
public function transfers(): MorphMany
306320
{
307-
return ($this instanceof WalletModel ? $this->holder : $this)
308-
->morphMany(config('wallet.transfer.model'), 'from');
321+
return $this->morphMany(config('wallet.transfer.model'), 'from');
309322
}
310323

311324
/**

0 commit comments

Comments
 (0)