I have a created_at field in my table. In most cases, when I want to read something from that table, I'd like the created_at to be formatted in a readable way (f.e. "5 hours ago").
I can do that with an accessor:
public function getCreatedAtAttribute($value){
return Carbon::parse($value)->diffForHumans();
}
But there are cases where I want the original date, which isn't possible with this solution.
Is there a way I can get both the original date and the formatted date automatically? I was thinking to create a separate accessor "getReadableCreatedAt" but I can't find a way to do it.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire