'integer', 'user_id' => 'integer', 'balance' => 'float' ]; public function user() { return $this->belongsTo(User::class); } public function transactions() { return $this->hasMany(WalletTransaction::class); } public function withdrawals() { return $this->hasMany(Withdrawal::class); } public function addBalance($amount, $description, $booking = null) { $this->balance += $amount; $this->save(); $this->transactions()->create([ 'type' => 'credit', 'amount' => $amount, 'description' => $description, 'booking_id' => $booking ? $booking->id : null ]); } public function deductBalance($amount, $description) { if ($this->balance < $amount) { throw new \Exception('Insufficient balance'); } $this->balance -= $amount; $this->save(); $this->transactions()->create([ 'type' => 'debit', 'amount' => $amount, 'description' => $description ]); } }