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

mgolami's avatar

how to convert and send date from model to controller

I was looking for a method to convert the jalali date to Gregorian using Carbon and store it in the corresponding DB table. I found the following method on youtube, in which after converting the date in the model, it sends it to the controller:

public function  setTaskDateAttribute($TaskDate)
{
    $this->attributes['TaskDate'] = CalendarUtils::convertNumbers($TaskDate, true);
    $this->attributes['TaskDate'] = CalendarUtils::createCarbonFromFormat('Y-m-d', $this->attributes['TaskDate'])->format('Y-m-d');
    dd($this->TaskDate);
}

in controller:

public function store(taskRequestStore $request,TaskService $service)
{
    dd($request->TaskDate);
   $attributes = $request->all(['office_id','TaskDate','Type','Priority_id']);
   $office = $service->create($attributes);
}

The dd function inside the setTaskDateAttribute function returns the Gregorian date value, but in the store function in the controller dd($request->TaskDate); The initial value of Jalali date is still returned. I want georgian date to be stored in table. It seems that the value of $this->TaskDate has no effect on the value of TaskDate in the controller. Please help me to fix the problem

0 likes
2 replies
Snapey's avatar

If it helps your searching, its Gregorian not Georgian

Please or to participate in this conversation.