我想'timemodified'根據同一查詢中的另一列更新所有沒有的行。
DB::table('sco_tracks')->where('timemodified', '')->update([
'timemodified' => Carbon::createFromFormat('Y-m-d H:i:s' , DB::raw('updated_at'))->timestamp
]);
使用此代碼,我得到:Data missing {"exception":"[object] (InvalidArgumentException(code: 0): A four digit year could not be found
uj5u.com熱心網友回復:
原始查詢將是
UPDATE sco_tracks t SET timemodified=UNIX_TIMESTAMP(created_at) WHERE timemodified IS NULL;
laravel 的代碼:
DB::table("sco_tracks")->where('timemodified','')->update(['timemodified'=>DB::raw('UNIX_TIMESTAMP(updated_at)')]);
如果 timemodified 欄位的值為 null 您可以使用以下代碼:
DB::table("sco_tracks")->whereNull('timemodified')->update(['timemodified'=>DB::raw('UNIX_TIMESTAMP(updated_at)')]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/420991.html
標籤:
下一篇:這個視圖究竟是從哪里加載的?
