Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chcrtech's avatar

Laravel Nova userTimezone not working as expected

So I read in the docs that I can set the timezone per user using the userTimezone method in the nova service provider. However, in Nova, it still says UTC next to all of my DateTime fields. When you edit a field, it shows the timezone I specified in the datetime editor but it saves it back to the database with the time I chose but in UTC. So in the editor, it says America/Detroit next to the field and if I enter noon, I would expect to see 16:00 in the database since UTC is currently 4 hours ahead. But I see 12:00 in the database.

0 likes
2 replies
LaryAI's avatar
Level 58

The issue you are facing with Laravel Nova's userTimezone method is likely due to a misconfiguration or misunderstanding of how it works. Here are a few steps you can take to troubleshoot and resolve the problem:

  1. Make sure you have properly registered the userTimezone method in your Nova service provider. Open the NovaServiceProvider.php file located in the app/Providers directory and ensure that the userTimezone method is defined correctly. Here's an example of how it should look:
use Laravel\Nova\Nova;

public function boot()
{
    Nova::userTimezone(function ($request) {
        return $request->user()->timezone;
    });
}
  1. Verify that the timezone attribute exists on your user model and is being populated correctly. Check the User model located in the app directory and ensure that the timezone attribute is defined and accessible. For example:
protected $fillable = [
    // other attributes
    'timezone',
];
  1. Confirm that the timezone attribute is being set correctly for each user. You can do this by checking the database records or by outputting the value of $request->user()->timezone in the userTimezone method. Make sure the value matches the expected timezone.

  2. Clear the Laravel cache to ensure that any changes you made to the code are reflected. Run the following command in your terminal:

php artisan cache:clear
  1. If the issue persists, consider checking the Laravel Nova documentation or reaching out to the Laravel Nova community for further assistance. It's possible that there may be a bug or a specific configuration requirement that you missed.

By following these steps, you should be able to resolve the issue with Laravel Nova's userTimezone method.

chcrtech's avatar

@LaryAI Thanks for the details -- I am afraid its still not working for me, I made a super simple repo with a test record and a userTimezone function and no joy.

My function is super simple: public function boot() { parent::boot();

    Nova::userTimezone(function (Request $request) {
        return "America/Detroit";
    });
}

I still see UTC in the record and when I edit the time, it shows Detroit but doesn't covert it to UTC on save.

My super simple repo is here: https://github.com/mnowak-umich/timezone-test

I posted to the Laravel Nova community but I was told my repo works fine on their machine and closed the ticket. :(

Please or to participate in this conversation.