Laravel nova diffForHumans DateTime

ⅰ亾dé卋堺 提交于 2021-01-28 18:32:44

问题


I have field last_active on users, I want display time with diffForHumans or time_from_now from Moment.js. How I can do it? Now I just use:

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

When I use:

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

I get undifined method diffForHumans.


回答1:


To my knowledge at the moment DateTime only supports format.

Since you want only to display, you can try Text field & display the humanise value.

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


来源:https://stackoverflow.com/questions/54265324/laravel-nova-diffforhumans-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!