belongsTo(Customer::class, 'customer_code', 'customer_code'); } /** * Get all balances for this account. */ public function balances() { return $this->hasMany(AccountBalance::class, 'account_number', 'account_number'); } /** * Get balance for a specific period. * * @param string $period Format: YYYY-MM * @return AccountBalance|null */ public function getBalanceForPeriod($period) { return $this->balances()->where('period', $period)->first(); } }