Search code examples
jsonapilaravel-10

Problem with Laravel and timestamp utc on different field


In the dabase i store the validation_parcellaire_at with :

$data = ['validation_parcellaire' => ($validation==1?\Carbon\Carbon::now()->toDateTimeString():null)];

In the database structure : enter image description here

The result is :

enter image description here

enter image description here

The other field have the same info for the update : enter image description here

When i retrieve the data with my software i get this :

enter image description here

And to retrieve in Laravel, i call the route which call :

use Illuminate\Http\JsonResponse;

     return $this->sendResponse(new UserResource($user), 'Utilisateur trouvé.');

Do you have any idea of what can happend to have the same data in the database and not the same result in the json with the API ?

Regards


Solution

  • After a week-end i found the solution, in the model of the table we need to cast the variable's type like that :

    protected $casts = [
        'email_verified_at' => 'datetime',
        'validation_parcellaire_at' => 'datetime',
    ];
    

    Regards