abu abu
abu abu

Reputation: 7028

Insert data in same row using Laravel

I am doing clock in and clock out. In this regard I would like to insert clock out time of user where the clock in time is already inserted. My query is like below.

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

Is it correct query ?

Upvotes: 0

Views: 309

Answers (1)

mbougarne
mbougarne

Reputation: 101

If clock_in && clock_out are a datetime format, you should convert them to that:

$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]);

Upvotes: 1

Related Questions