Laravel

How do I get the difference of time in human-readable format with Laravel

Pinterest LinkedIn Tumblr

By default, Eloquent converts created_at and updated_at columns to instances of Carbon. So if you are fetching the data using Eloquent, then you can do it as below.

$object->updated_at->diffForHumans();

If you want to customize the fields that will be mutated automatically, then within your model, you can customize them as you wish.

// Carbon instance fields
protected $dates = ['created_at', 'updated_at', 'deleted_at'];

Write A Comment