Total Complexity | 3 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
17 | trait HasWallets |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * The variable is used for the cache, so as not to request wallets many times. |
||
22 | * WalletProxy keeps the money wallets in the memory to avoid errors when you |
||
23 | * purchase/transfer, etc. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | private $_wallets = []; |
||
28 | |||
29 | /** |
||
30 | * method of obtaining all wallets |
||
31 | * |
||
32 | * @return MorphMany |
||
33 | */ |
||
34 | public function wallets(): MorphMany |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Get wallet by slug |
||
41 | * |
||
42 | * $user->wallet->balance // 200 |
||
43 | * or short recording $user->balance; // 200 |
||
44 | * |
||
45 | * $defaultSlug = config('wallet.wallet.default.slug'); |
||
46 | * $user->getWallet($defaultSlug)->balance; // 200 |
||
47 | * |
||
48 | * $user->getWallet('usd')->balance; // 50 |
||
49 | * $user->getWallet('rub')->balance; // 100 |
||
50 | * |
||
51 | * @param string $slug |
||
52 | * @return WalletModel|null |
||
53 | */ |
||
54 | public function getWallet(string $slug): ?WalletModel |
||
66 |