Issue
I want to update all row that has no 'timemodified'
based on another column from the same query.
DB::table('sco_tracks')->where('timemodified', '')->update([
'timemodified' => Carbon::createFromFormat('Y-m-d H:i:s' , DB::raw('updated_at'))->timestamp
]);
With this code I get: Data missing {"exception":"[object] (InvalidArgumentException(code: 0): A four digit year could not be found
Solution
the raw query would be
UPDATE sco_tracks t SET timemodified=UNIX_TIMESTAMP(created_at) WHERE timemodified IS NULL;
the code for laravel:
DB::table("sco_tracks")->where('timemodified','')->update(['timemodified'=>DB::raw('UNIX_TIMESTAMP(updated_at)')]);
and if the value of timemodified field is null you can use this code:
DB::table("sco_tracks")->whereNull('timemodified')->update(['timemodified'=>DB::raw('UNIX_TIMESTAMP(updated_at)')]);
Answered By - Aria Shahdadi
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.