Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robert_Wlliams's avatar

Storing date on request in created at entity.

Actually I have Installment management system. system is working perfectly but now i want that when i sell my product i can use any desired date and system automatically generate installments dates in advance. What system is actually doing is getting todays date from carbon and then adding installment difference. below is my code.

  $instalment = Instalment::findOrFail($request->instalment_id);
                            $parIns = round($order->due_amount / $instalment->time);
                            $tt = '';
                            for ($i=1;$i<=$instalment->time;$i++){
                                $insTime['order_instalment_id'] = $orderInss->id;
                                $insTime['amount'] = $parIns;
                                $insTime['amount'] = $parIns;
                                $tt = Carbon::parse($tt)->addDays($instalment->difference);
                                $insTime['pay_date'] = $tt;
                                InstalmentTime::create($insTime);
                            }
0 likes
6 replies
drewdan's avatar

I am not sure I understand the question you are asking. Do you wish to set the created_at date to something different to the current time?

Snapey's avatar

i want that when i sell my product i can use any desired date

How are you capturing the desired date?

Snapey's avatar

parse the passed date with Carbon. Use it for the first installment and then repeat by adding interval to the date. No need to keep parsing the date

$tt = Carbon::parse($request->date);
$insTime['order_instalment_id'] = $orderInss->id;
$insTime['amount'] = $parIns;

for ($i=1;$i<=$instalment->time;$i++){
    $insTime['pay_date'] = $tt;
    InstalmentTime::create($insTime);
    $tt->addDays($instalment->difference);
}
1 like
Robert_Wlliams's avatar

@snapey Sir by using your code it is storing the correct date but if I enter any date before today like 3rd-Aug-2020 instead of providing date after 30 days like next due installment date is 3rd-Sept-2020 it is giving me 25th-Sept-2020 and so on.

Please or to participate in this conversation.