Change Timezone In Laravel


Answer :

go to the file config/app.php and look for this entry:

/* |-------------------------------------------------------------------------- | Application Timezone |-------------------------------------------------------------------------- | | Here you may specify the default timezone for your application, which | will be used by the PHP date and date-time functions. We have gone | ahead and set this to a sensible default for you out of the box. | */  'timezone' => 'Asia/Tehran', //There will be default 'UTC' here 

As you can see, UTC is a default value for Laravel. So you can easily change it here to, like:

'timezone' => 'Asia/Tehran', - See full list PHP Supported Timezones

After changes app.php you should run this command php artisan config:cache


After update app.php run below command and check

php artisan config:cache php artisan cache:clear 

You can create below type of route for clear cache in laravel

Route::get('/clear-cache', function() {      $configCache = Artisan::call('config:cache');     $clearCache = Artisan::call('cache:clear');     // return what you want }); 

I wonder why Laravel team didn't put this inside .env. It seems like best place for parameter like that.

Add this to .env:

TIME_ZONE = 'put_your/timezone_here' 

and in /config/app.php change:

'timezone' => 'UTC', 

to:

'timezone' => env('TIME_ZONE', 'UTC'), 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?