File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 1313use Bavix \Wallet \Internal \Service \MathServiceInterface ;
1414use Bavix \Wallet \Internal \Service \UuidFactoryServiceInterface ;
1515use Bavix \Wallet \Services \AtomicServiceInterface ;
16+ use Bavix \Wallet \Services \CastServiceInterface ;
1617use Bavix \Wallet \Services \RegulatorServiceInterface ;
1718use Bavix \Wallet \Traits \CanConfirm ;
1819use Bavix \Wallet \Traits \CanExchange ;
1920use Bavix \Wallet \Traits \CanPayFloat ;
2021use Bavix \Wallet \Traits \HasGift ;
2122use DateTimeInterface ;
2223use Illuminate \Database \Eloquent \Model ;
24+ use Illuminate \Database \Eloquent \Relations \HasMany ;
2325use Illuminate \Database \Eloquent \Relations \MorphTo ;
2426use Illuminate \Database \RecordsNotFoundException ;
2527use 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}
Original file line number Diff line number Diff 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 ());
You can’t perform that action at this time.
0 commit comments