This package provides a trait you can add to an Eloquent model that will automatically create human-readable timestamp diffs using Carbon.
Laravel | PHP | Package Version |
---|---|---|
6 | 8.0, 7.4, 7.3 | 2 |
7 | 8.0, 7.4, 7.3 | 2 |
8 | 8.1, 8.0, 7.4, 7.3 | 3 |
9 | 8.1, 8.0 | 4 |
10 | 8.1 | 5 |
To install the package run:
composer require chrisdicarlo/eloquent-human-timestamps
Add the ChrisDiCarlo\EloquentHumanTimestamps\HumanTimestamps trait to a model that has timestamp columns, e.g.:
use ChrisDiCarlo\EloquentHumanTimestamps\HumanTimestamps;
class Foobar
{
use HumanTimestamps;
...
}
To get the human-readable attribute, simply retrieve the timestamp normally but append _for_humans to the name, e.g. created_at_for_humans, updated_at_for_humans.