Skip to content

Commit

Permalink
Merge pull request #878 from gkmk/10.x-received-transfers-update
Browse files Browse the repository at this point in the history
[10.x] received transfers
  • Loading branch information
rez1dent3 authored Feb 1, 2024
2 parents 4ff4ef5 + 2071af4 commit 1a58e93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Bavix\Wallet\Traits\HasGift;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\RecordsNotFoundException;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -162,4 +163,14 @@ protected function initializeMorphOneWallet(): void
{
$this->uuid = app(UuidFactoryServiceInterface::class)->uuid4();
}

/**
* returns all the receiving transfers to this wallet.
*
* @return HasMany<Transfer>
*/
public function receivedTransfers(): HasMany
{
return $this->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id');
}
}
2 changes: 2 additions & 0 deletions tests/Units/Service/AtomicServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function testBlock(): void
);

self::assertSame(1, $user2->transfers()->count());
self::assertSame(2, $user2->wallet->receivedTransfers()->count());
self::assertSame(1, $user1->wallet->receivedTransfers()->count());
self::assertSame(2, $user1->transfers()->count());
self::assertSame(3, $user2->transactions()->count());
self::assertSame(4, $user1->transactions()->count());
Expand Down

0 comments on commit 1a58e93

Please sign in to comment.