how to change database timezone in lumen?

Viewed 317

when insert with eloquent or query builder in lumen project, created_at is wrong and saved UTC. I set in app.php

date_default_timezone_set('Asia/Tehran');

and in env

DB_TIMEZONE='+04:30'

and in env

APP_TIMEZONE=Asia/Tehran

but again created at is wrong.i think is bug of lumen.

2 Answers

Add this variable to your env file.

APP_TIMEZONE=Asia/Tehran

After you have added the variable, run the command below.

php artisan optimize

If your MySQL server uses the same time zone with PHP, add this code in app.php:

date_default_timezone_set('Asia/Tehran');
$_ENV['DB_TIMEZONE'] = date('P');

In this example date function returns +04:30 or +03:30 based on daylight saving time changes.

Related