Laravel Nova diffForHumans DateTime [英] Laravel nova diffForHumans DateTime

查看:70
本文介绍了Laravel Nova diffForHumans DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对用户有一个last_active字段,我想使用diffForHumans或Moment.js中的 time_from_now 显示时间.我该怎么办?现在我只用:

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(),

当我使用时:

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

我得到了未定义的方法 diffForHumans .

I get undifined method diffForHumans.

推荐答案

据我所知, DateTime 目前仅支持 format .

To my knowledge at the moment DateTime only supports format.

由于只想显示,因此可以尝试 Text 字段&显示人性化的价值.如果您的列可能为空,请确保进行检查,否则会出现错误.

Since you want only to display, you can try Text field & display the humanise value. If your column might be null be sure to check for that otherwise you will get an error.

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

这篇关于Laravel Nova diffForHumans DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆