Laravel Nova没有显示记录的userTimezone

问题描述

我有一个问题困扰着我整个下午。

使用Laravel Nova,在资源中使用DateTime类时:

DateTime::make('End','end_date')->required(),

它会自动显示在本地时区(https://nova.laravel.com/docs/3.0/resources/date-fields.html)中。但是,当我阅读文档时,它说要在服务提供商的启动方法中设置userTimezone,以定义资源的时区:

Nova::userTimezone(function (Request $request) {
    // app.timezone = 'UTC'
    return 'Europe/Warsaw';
});

我已经做到了,但是在所有资源上它仍以nova表示时区,而不是指定的时区。

注意事项:

缓存已清除:

PHP artisan config:cache
PHP artisan config:clear
PHP artisan cache:clear

重新加载Nova并重建页面

然后我的问题是,如何使Nova DateTime资源全部位于指定的时区?

解决方法

您应该在应用程序Nova::userTimezone的{​​{1}}方法中调用此boot

NovaServiceProvider