在我的Kununtu 18下的Laravel 5.8 / mysql 5.7.28中,我有一个问题,添加新行created_at字段充满了-3小时的差异。
在我的控制下:
public function add_hostel_enquery()
{
$request = request();
$requestData = $request->all();
$newHostelInquery = new HostelInquery();
$newHostelInquery->creator_id = ! empty($requestData['creator_id']) ? $requestData['creator_id'] : '';
$newHostelInquery->hostel_id = ! empty($requestData['hostel_id']) ? $requestData['hostel_id'] : '';
$newHostelInquery->full_name = ! empty($requestData['full_name']) ? $requestData['full_name'] : '';
$newHostelInquery->email = ! empty($requestData['email']) ? $requestData['email'] : '';
$newHostelInquery->phone = ! empty($requestData['phone']) ? $requestData['phone'] : '';
$newHostelInquery->info = ! empty($requestData['info']) ? $requestData['info'] : '';
$newHostelInquery->start_date = ! empty($requestData['start_date']) ? $requestData['start_date'] : '';
$newHostelInquery->end_date = ! empty($requestData['end_date']) ? $requestData['end_date'] : '';
$newHostelInquery->request_callback = !empty($requestData['request_callback']) ? "Y" : 'N';
try {
DB::beginTransaction();
$newHostelInquery->save();
DB::commit();
...
在config / app.php中:
'timezone' => 'Europe/Kiev',
在我的操作系统中,我有相同的时区。
数据库创建为:
Schema::create('hostel_inqueries', function(Blueprint $table)
{
$table->increments('id');
...
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->nullable();
...
});
我知道更新行我解决了代码问题:
$hostelInquery->updated_at = Carbon::now(config('app.timezone'));
$hostelInquery->save();
如何使created_at在insert上填充?
最佳答案
我不使用$ table-> timestamps()来设置我创建的服务器,
所以我在mysql部分找到了决策设置:
SET GLOBAL time_zone = '+3:00';
并检查:
SELECT @@global.time_zone, @@session.time_zone;
关于mysql - 添加新行created_at字段的时间差为-3小时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58557071/