0

I'm using Lumen 5.2 to access MySql. After listen the query and log the sql, I see

[object] (Illuminate\\Database\\Events\\QueryExecuted: {\"sql\":\"insert into
`RedEnvelopes` (`User_id`, `amount`, `remain`, `expiredAt`, `to_User_id`,        
`message`, `type`, `dividend`, `updatedAt`, `createdAt`) values (?, ?, ?, ?, 
?, ?, ?, ?, ?, ?)\",\"bindings\":
[5000219,\"1\",\"1\",1478073412,\"8000228\",\"你的名字\",1,1,\"2016-11-02 
15:51:52\",\"2016-11-02 15:51:52\"],\"time\":0.77,\"connection\":
{},\"connectionName\":\"mysql\"})

And using Model::find() to get the record, the return is coherent with the sql above. But when I access MySql server directly and get the record by SQL, the createdAt and updatedAt are later than the the binding values by 8 hours.

I'm totally confused. Anyone else have encountered this question? I need some help.

limen
  • 67
  • 7

1 Answers1

0

I think the problem could be resolved by 3 steps.

First, set the timezone to your local timezone. Mine is Asia/Shanghai. See .env

APP_TIMEZONE=Asia/Shanghai 

Second, set app timezone in config/app.php

'timezone' => env('APP_TIMEZONE'),

Last, change created_at/updated_at column to datetime type.

limen
  • 67
  • 7