Laravel nova diffForHumans 日期时间

Laravel nova diffForHumans DateTime

我有关于用户的字段 last_active,我想使用 diffForHumans 或 Moment.js 中的 time_from_now 显示时间。我该怎么做?现在我只使用:

DateTime::make('Activiy', 'last_active')
            ->exceptOnForms(),

当我使用:

DateTime::make('Activiy', 'last_active')->diffForHumans()
            ->exceptOnForms(),

我得到未定义的方法 diffForHumans

据我所知目前DateTime只支持format

因为你只想显示,你可以试试Text字段&显示人性化的值。如果您的列可能为空,请务必进行检查,否则会出现错误。

Text::make('Activiy', 'last_active')
    ->displayUsing(function($lastActive) {
        if ($lastActive === null) {
            return null;
        }
        return $lastActive->diffForHumans();
    })
    ->exceptOnForms(),