在将数据创建到数据库后,我看到错误的数据时间为created_at
和updated_at
到phpMyAdmin
,
我在laravel Asia/tehran
文件中设置了config/app
,并且我的系统日期时间正确并已更新,当我使用now()
登录carbon
时,得到以下输出:
Carbon @1532117471 {#1179 ▼
date: 2018-07-21 00:41:11.142496 Asia/Tehran (+04:30)
}
这对我的系统日期时间是正确的,created_at
和updated_at
的数据库日期时间是:2018-07-20 19:58:26
当我使用Laravel作业队列时会发生此问题
此时的时钟是00:41:11
而不是19:58:26
,我该如何解决此问题并解决该问题?
答案 0 :(得分:0)
您正在寻找laravel的created_at和Updated_at。它们被用作根据您的幼虫的 country spending_type total_spending
<chr> <chr> <int>
1 uk economic 880
2 uk military 1900
3 usa economic 7080
4 usa military 13900
时区创建时间的时间戳。
您该如何更改?
选项1.转到config/app
并将时区更改为所需的时区。
选项2。使用mutators管理在创建的模型。
https://laravel.com/docs/5.6/eloquent-mutators#defining-a-mutator
在口才模型上,您只需创建:
config/app.php
注意:要触发此功能,您需要使用Eloquent的Create,如下所示:
public function setCreatedAtAttribute($value) {
/*
$value is the value it is going to initially be stored
This date format is required due to mySql's timestamp restriction.
However, you can create a date with Carbon, and as long as you format into that
structure Y-d-m H:i:s it will do just fine
*/
$this->attributes['created_at'] = Date("Y-m-d H:i:s);
}