Wednesday, 14 July 2021

Laravel Change Timezone

Laravel Change Timezone


By default UTC is set as a default timezone in laravel instalaltion.We can change it very easily.









Step 1 : Adjust the configuration:

    
Navigate to the config/app.php file within your Laravel project.




Locate the 
timezone setting.


Replace the default value UTC with your desired timezone string, ensuring it's a valid PHP timezone identifier  (e.g., Asia/Karachi, America/Los_Angeles, Europe/London).

// 'timezone' => 'UTC',
   'timezone' => 'Asia/Karachi',



Step 2:Clear configuration caches:

After changing the timezone we need to run following commands

php artisan cache:clear
php artisan config:clear


These commands will clear all config and other cache.

Additional considerations:

  • Environment variable: For flexibility across environments, consider setting the timezone using an environment variable:

'timezone' => env('APP_TIMEZONE', 'UTC'),
In env file we can define APP_TIMEZONE constant with the required timezone

That's it. If you have any question please feel fee to ask.




No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...