xxxxxxxxxx
Look up this package below, you can Automatically Set a Local Timezone for Users:
https://github.com/jamesmills/laravel-timezone
Credit: https://laravel-news.com/laravel-timezone
xxxxxxxxxx
// on a date column
$user->created_at->timezone('Asia/Kolkata')->toDateTimeString()
// Directly on a Carbon instance
Carbon\Carbon::parse('2018-01-22 04:09:31')->timezone('Asia/Kolkata')->toDateTimeString()
Check out these Links
Credit: https://laracasts.com/discuss/channels/laravel/change-date-timezone-in-laravel-project-while-fetching-date?page=1&replyId=576247
Actual Article: https://qcode.in/managing-users-timezone-in-laravel-app/
xxxxxxxxxx
// config/app.php
return [
// ...
'timezone' => 'Asia/Kolkata',
// ...
];
xxxxxxxxxx
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->app->bind(Carbon::class, function (Container $container) {
return new Carbon('now', 'Europe/Brussels');
});
}
}
xxxxxxxxxx
/*
|--------------------------------------------------------------------------
| 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' => 'Europe/Paris',