@php $details_id = 0 ; $where = [] ; /* if(($top_payment_amount + $current_payment_amount) > $down_payment_amount){ $current_payment_amount = $down_payment_amount - $top_payment_amount ; } */ @endphp @for ($i = 1; $i <= $new_payment_head_number; ++$i) @php $payment_name="Down Payment ". ($i + $exist_row) ; $where = [] ; $where[] = ['schedule_id','=',$schedule_id]; $where[] = ['payment_name','=',$payment_name]; $plotSchedule = find('ScheduleDetails',$where,'id','desc','first'); $details_id = isset($plotSchedule)?$plotSchedule->id:0; $top_payment_amount += $current_payment_amount ; $difference = $down_payment_amount - $top_payment_amount ; if($difference < $current_payment_amount){ $current_payment_amount = $difference ; } $time = strtotime($dpDate); $dpDate = date("Y-m-d", strtotime("+1 month", $time)); @endphp {{ ($i + $exist_row) }} {{ $payment_name }} @endfor