How to increment database field values by 1 in Laravel

前端 未结 1 1338
情深已故
情深已故 2021-01-27 08:30

I have a table student attendance.

Fields/data sample

id | studid | cls_id | smonth | syear | total_p | total_a
1  |   20   |   2    |           


        
1条回答
  •  粉色の甜心
    2021-01-27 09:14

    I think u just want to update each record of total_p and total_a column just make it simple:

    //get the id of student
    $student_id = Input::get('student_id');
    $present = Input::get('status'); //dropdown value 0,1
    //You need a model for your table let say:
    #Student.php
    count() && $status==1 ){ //status 1 = present
      $query->total_p += 1; //plus one value in the total_p column in the tbl.
      $query->save();
     }else{
      $query->total_a +=1;
      $query->save();
     }
    }
    

    0 讨论(0)
提交回复
热议问题