jeudi 29 décembre 2016

How to update a mysql table having null with some data using laravel?

I have a table called breaks. This table has columns[id, AttendanceId, start, end, breakTime, Remarks]. A user can take multiple breaks. So, this table can have multiple entries for one user. For eg: If I take 3 breaks and among 3 the first two were complete breaks(ie; it has start and end time.). However, the last break I put start and directly loggout from the system. So, the current table will be filled with 2 complete breaks and one incomplete breaks[Remarks will show Inactive for 2 breaks and Active for last break.]. Now, while logging out I have to calculate the total work time. I am taking the sums of all the breaks taken and then reduce it from : [(login time - logout time) - sum(All complete break times from break table].

Currently, my code is not considering the last break and its just taking the complete breaks sums and deducting it from the total time.

So, I tried updating the last break end time finding Active break. But I am not able to do so. Its giving me Call to a member function update() on null which is indeed correct.

How do I update the null cell, infact with the logout time so that I can consider all the breaks for calculating the total work time.

Here is my code:

$OT=Carbon::now('Asia/Kolkata');
$getRemarks = TakeBreak::orderBy('Id', 'desc')->where('AttendanceId',Session::get('AttendanceId'))->first();
if ($getRemarks->Remarks == "Active"){
   DB::table('breaks')->orderBy('Id','desc')->where('Id', Session::get('AttendanceId'))->first()
                                       ->update(
                                            [
                                                'End' => date('H:i:s', mktime(0,$OT)),
                                                'Remarks' => "Inavtive"
                                            ])
                    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ihdbLN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire