php – 查询构建器不插入时间戳
作者:互联网
我正在使用“查询”构建器来插入数据,所有字段都已插入,但是像created_at和updated_at这样的时间戳没有插入,它们都具有默认的0:0:0值
我的插入查询是
$id = DB::table('widgets')
->insertGetId(array(
'creator' => Auth::user()->id,
'widget_name' => $request->input('widget_name'),
'pages' => json_encode($request->input('pages')),
'domain' => $request->input('domain'),
"settings" => $settings,
));
解决方法:
好吧.字段created_at,update_at和deleted_at是Eloquent的“部分”.您使用Query Builder =>插入不会影响这两个字段(created_at和updated_at).你应该手动定义它:
$id = DB::table('widgets')
->insertGetId(array(
'creator' => Auth::user()->id,
'widget_name' => $request->input('widget_name'),
'pages' => json_encode($request->input('pages')),
'domain' => $request->input('domain'),
"settings" => $settings,
"created_at" => \Carbon\Carbon::now(), # new \Datetime()
"updated_at" => \Carbon\Carbon::now(), # new \Datetime()
));
标签:query-builder,php,laravel,mysql 来源: https://codeday.me/bug/20191005/1856946.html