使用 Laravel 在同一行中插入数据
Insert data in same row using Laravel
我正在打卡打卡。在这方面,我想在已经插入时钟的地方插入用户的时钟输出时间。我的查询如下。
DB::table('clocks')
->where('user_id', Auth::user()->id)
->latest('created_at')->first()
->update(array('clock_out' => $request->clock_in));
查询是否正确?
如果 clock_in && clock_out 是日期时间格式,您应该将它们转换为:
$getClock = DB::table('clocks')>where('user_id', Auth::id())
->orderBy('created_at')->first();
$clockIn = date('Y-m-d H:i:s',strtotime($request->clock_in));
$getClock->update(['clock_out' => $clockIn]);
我正在打卡打卡。在这方面,我想在已经插入时钟的地方插入用户的时钟输出时间。我的查询如下。
DB::table('clocks')
->where('user_id', Auth::user()->id)
->latest('created_at')->first()
->update(array('clock_out' => $request->clock_in));
查询是否正确?
如果 clock_in && clock_out 是日期时间格式,您应该将它们转换为:
$getClock = DB::table('clocks')>where('user_id', Auth::id())
->orderBy('created_at')->first();
$clockIn = date('Y-m-d H:i:s',strtotime($request->clock_in));
$getClock->update(['clock_out' => $clockIn]);