I am experiencing something quite weird for any Eloquent Model with Laravel 7!
P.S.: I've run on every test I did:
php artisan optimize:clear
I don't know what I am missing here!
I won't post any code because that's a simple CRUD with Model Bindings.
When saving the created_at and updated_at fields, it is correctly saved in the MySQL with my timezome "America/Sao_Paulo".
But if I do this in any controler:
return $model->get()
or
return $model->paginate()
or
Model::all()
I get the response:
{
"data": [
{
... other fields
"created_at": "2020-08-23T15:22:41.000000Z",
"updated_at": "2020-08-23T15:22:41.000000Z"
}
]
}
And it returns the wrong time with +1 hour.
However, here is where things get weird... if I print_r() any of them, I get the corret time!
Array
(
... other fields
[created_at] => 2020-08-23 12:22:41
[updated_at] => 2020-08-23 12:22:41
)
I tried to use:
public function getDateFormat()
{
return 'Y-m-d H:i:s';
}
But no effect!
Thanks in Advance!