Issue when casting to datetime format in Laravel
I'm having an issue with timestamps in my Laravel app. Our database stores timestamps in CEST, but when I cast them to a datetime object, Laravel automatically converts them to UTC, even though my timezone is set to CEST in the config file.
'timezone' => 'Europe/Brussels',
Here's an example of how I'm casting it:
protected $casts = [
'new' => 'datetime'
];
When I don't cast to datetime, the problem goes away, but for some parts of the app, I need the datetime format.
I know I can manually convert it like this:
Carbon::parse($new)->setTimezone('CEST')
But I want to avoid doing this conversion manually every time. Is there a way to cast it to datetime and have it automatically use CEST instead of UTC?
Any help or explanation on why this happens and how to fix it would be greatly appreciated!
Please or to participate in this conversation.