'decimal:2', 'used_days' => 'decimal:2', 'remaining_days' => 'decimal:2', 'carried_forward' => 'decimal:2', 'manual_adjustment' => 'decimal:2', ]; /** * Get the employee. */ public function employee() { return $this->belongsTo(User::class, 'employee_id'); } /** * Get the leave type. */ public function leaveType() { return $this->belongsTo(LeaveType::class); } /** * Get the leave policy. */ public function leavePolicy() { return $this->belongsTo(LeavePolicy::class); } /** * Get the user who created the balance. */ public function creator() { return $this->belongsTo(User::class, 'created_by'); } /** * Calculate remaining days. */ public function calculateRemainingDays() { $this->remaining_days = ($this->allocated_days + $this->carried_forward + $this->manual_adjustment) - $this->used_days; return $this->remaining_days; } }