Skip to content

Commit ff60104

Browse files
committed
Add received transfers function for v10
1 parent 4ff4ef5 commit ff60104

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Models/Wallet.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
use Bavix\Wallet\Internal\Service\MathServiceInterface;
1414
use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface;
1515
use Bavix\Wallet\Services\AtomicServiceInterface;
16+
use Bavix\Wallet\Services\CastServiceInterface;
1617
use Bavix\Wallet\Services\RegulatorServiceInterface;
1718
use Bavix\Wallet\Traits\CanConfirm;
1819
use Bavix\Wallet\Traits\CanExchange;
1920
use Bavix\Wallet\Traits\CanPayFloat;
2021
use Bavix\Wallet\Traits\HasGift;
2122
use DateTimeInterface;
2223
use Illuminate\Database\Eloquent\Model;
24+
use Illuminate\Database\Eloquent\Relations\HasMany;
2325
use Illuminate\Database\Eloquent\Relations\MorphTo;
2426
use Illuminate\Database\RecordsNotFoundException;
2527
use Illuminate\Support\Str;
@@ -162,4 +164,17 @@ protected function initializeMorphOneWallet(): void
162164
{
163165
$this->uuid = app(UuidFactoryServiceInterface::class)->uuid4();
164166
}
167+
168+
/**
169+
* returns all the receiving transfers to this wallet.
170+
*
171+
* @return HasMany<Transfer>
172+
*/
173+
public function receivedTransfers(): HasMany
174+
{
175+
return app(CastServiceInterface::class)
176+
->getWallet($this, false)
177+
->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id')
178+
;
179+
}
165180
}

tests/Units/Service/AtomicServiceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function testBlock(): void
3535
);
3636

3737
self::assertSame(1, $user2->transfers()->count());
38+
self::assertSame(2, $user2->wallet->receivedTransfers()->count());
39+
self::assertSame(1, $user1->wallet->receivedTransfers()->count());
3840
self::assertSame(2, $user1->transfers()->count());
3941
self::assertSame(3, $user2->transactions()->count());
4042
self::assertSame(4, $user1->transactions()->count());

0 commit comments

Comments
 (0)