I want Laravel Nova to handle a DateTime field (stored in the database in UTC) in a custom timezone based on the Model and not in the User's timezone it does by default:
https://nova.laravel.com/docs/3.0/resources/date-fields.html#timezones
The field is for event start times at various locations across timezones throughout the United States. It does not make sense to display them in the user's timezone since they will be sorted with a location filter or viewed in respect to the Location model.
Does anyone have a solution for how to handle this use case?
Try this instead, create new column in users table called timezone.
Schema::table('users', function (Blueprint $table) {
$table->string('timezone')->nullable();
});
In User resource create timezone field like this
Timezone::make('Timezone')
->default('yourtimezone'),
then in novaServiceProvider add following in boot()
Nova::userTimezone(function (Request $request) {
return $request->user()->timezone;
});
this allows you to have control over user timezones. Once user is logged in with the specific timezone he/she will be able to create events at various locations across timezones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With