File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 2020use Bavix \Wallet \Traits \HasGift ;
2121use DateTimeInterface ;
2222use Illuminate \Database \Eloquent \Model ;
23+ use Illuminate \Database \Eloquent \Relations \HasMany ;
2324use Illuminate \Database \Eloquent \Relations \MorphTo ;
2425use Illuminate \Database \RecordsNotFoundException ;
2526use Illuminate \Support \Str ;
@@ -162,4 +163,14 @@ protected function initializeMorphOneWallet(): void
162163 {
163164 $ this ->uuid = app (UuidFactoryServiceInterface::class)->uuid4 ();
164165 }
166+
167+ /**
168+ * returns all the receiving transfers to this wallet.
169+ *
170+ * @return HasMany<Transfer>
171+ */
172+ public function receivedTransfers (): HasMany
173+ {
174+ return $ this ->hasMany (config ('wallet.transfer.model ' , Transfer::class), 'to_id ' );
175+ }
165176}
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