Level 102
What is 31072021 representing. Days since x? What date?
And you can use a mutator
public function getCreatedAtAttribute($value)
{
return $value;//calculate date based on value
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In MySQL table I have one field "Created_at" which have datatype varchar & the date is stored in this format "31072021". I want to convert string date to datetime without change the datatype in my table. I tried to use protected $casts = ['Created_at' => 'datetime:Y-m-d']; In the model Also I tried to use withCasts([Created_at' => datetime:Y-m-d]) but I'm not able to convert string to datetime ( like 31072021 => 2021-07-31 ). Can anyone tell me how to do this?
Please or to participate in this conversation.