How to change created_at to a timestamp during or after querying.
I have my data in this form:
$data = Notice::find(1)->first();
What I want to achieve is to convert the created_at attribute value in this object to a timestamp.
I know I could override the $dateFormat attribute in my model to get a custom value in my db. However, I want to only customize it when retrieving the result. Is there a way to format the column during querying or better still modify just the created attribute to be a timestamp without necessarily duplicating objects here and there?
@abusalameh Thanks. But if I do that, it will means I will be storing a different date time format in my database. I want to maintain the default datetime but only format the created_at of the data returned after the query.
Sorry, I thought my question was clear enough.
I was actually looking for a way to format one of the field or attribute of my data object during the querying process. It seems to me there is nothing like that, so I'm now falling back to way of mutating the object containing my data without necessarily looping through this object.