public function nthInstallmentDate($n = 1) { $date = $this->installmentGraceDate()->copy(); if ($this->loan->isWeeklyInstallment()) { $date->addWeeks($n); } else { if ($date->day == 31) { $date->firstOfMonth()->addMonths($n)->lastOfMonth(); } else { $date->addMonths($n); } } return $date; }