I don't know why exactly you are manipulating dates inside method. Just simply define your column as a carbon instance in your model-
protected $dates = ['birth_date', 'some_more'];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my model =>
public function setBirthDateAttribute($date)
{
$this->attributes['birth_date'] = Carbon::createFromFormat('M d,Y',$date)->toDateString();
}
public function getBirthDateAttribute($value)
{
return Carbon::parse($value)->toFormattedDateString();
}
after dd()
#attributes: array:11 [▼
"name" => "Eliyas Hossain"
"father_name" => null
"mother_name" => null
"gender" => "Male"
"birth_date" => "2017-06-01"
]
In my controller =>
public function update(EmployeeFormUpdate $request, EmployeePersonalDetail $personalDetail)
{
dd($personalDetail->birth_date = $request->input('birth_date'));
return redirect('dashboard/employee')->with(['message'=>'Employee Updated Successfully.','type'=>'success']);
}
after hit submit button
InvalidArgumentException in Carbon.php line 582: Unexpected data found. in Carbon.php line 582 at Carbon::createFromFormat('M d,Y', 'Jun 1, 2017') in EmployeePersonalDetail.php line 65 at EmployeePersonalDetail->setBirthDateAttribute('Jun 2, 2017') in HasAttributes.php line 519 at Model->setAttribute('birth_date', 'Jun 2, 2017') in Model.php line 1249 at Model->__set('birth_date', 'Jun 2, 2017') in EmployeeController.php line 155
Please someone help me to solve this problem.
I solved my problem :) Here is the code in my model =>
public function setBirthDateAttribute($date)
{
$this->attributes['birth_date'] = date("Y-m-d",strtotime($date));
}
public function getBirthDateAttribute($value)
{
return Carbon::parse($value)->toFormattedDateString();
}
Please or to participate in this conversation.