Total Complexity | 4 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Coverage | 33.33% |
Changes | 0 |
1 | <?php |
||
16 | class Wallet extends Model implements Customer, WalletFloat |
||
17 | { |
||
18 | |||
19 | use CanBePaidFloat; |
||
|
|||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $fillable = [ |
||
25 | 'holder_type', |
||
26 | 'holder_id', |
||
27 | 'name', |
||
28 | 'slug', |
||
29 | 'description', |
||
30 | 'balance', |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $casts = [ |
||
37 | 'balance' => 'int', |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | 21 | public function getTable(): string |
|
44 | { |
||
45 | 21 | if (!$this->table) { |
|
46 | 21 | $this->table = \config('wallet.wallet.table'); |
|
47 | } |
||
48 | |||
49 | 21 | return parent::getTable(); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function calculateBalance(): bool |
||
56 | { |
||
57 | $this->attributes['balance'] = $this->transactions() |
||
58 | ->where('wallet_id', $this->getKey()) |
||
59 | ->where('confirmed', true) |
||
60 | ->sum('amount'); |
||
61 | |||
62 | return $this->save(); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return BelongsToMany |
||
67 | */ |
||
68 | public function holder(): BelongsToMany |
||
71 | } |
||
72 | |||
73 | } |
||
74 |