【问题标题】:Insert data in same row using Laravel使用 Laravel 在同一行中插入数据
【发布时间】:2020-01-18 02:05:55
【问题描述】:

我正在上班和下班。在这方面,我想在已经插入时钟的地方插入用户的下班时间。我的查询如下。

    DB::table('clocks')
            ->where('user_id', Auth::user()->id)
            ->latest('created_at')->first()
            ->update(array('clock_out' => $request->clock_in));

查询是否正确?

【问题讨论】:

    标签: mysql laravel-5.7


    【解决方案1】:

    如果 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]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 2018-06-23
      • 2022-01-25
      • 2022-08-11
      • 2014-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多