Skip to content

Commit 19378bd

Browse files
committed
optimize get wallet
1 parent 9c19662 commit 19378bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Traits/HasWallets.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ trait HasWallets
4343
*/
4444
public function getWallet(string $slug): ?WalletModel
4545
{
46+
if (\array_key_exists($slug, $this->_wallets)) {
47+
return $this->_wallets[$slug];
48+
}
49+
50+
if ($this->relationLoaded('wallets')) {
51+
$wallets = $this->getRelation('wallets');
52+
foreach ($wallets as $wallet) {
53+
$this->_wallets[$wallet->slug] = $wallet;
54+
}
55+
}
56+
4657
if (!\array_key_exists($slug, $this->_wallets)) {
4758
$this->_wallets[$slug] = $this->wallets()
4859
->where('slug', $slug)

0 commit comments

Comments
 (0)