title: how to use increment() and decrement() in laravel
body: <p>I have a table <code>total_count</code></p>
  
  <pre><code>+----+--------+-------+------+---------+---------+---------+
  | id | studid | month | year | acls_id | total_p | total_a |
  +----+--------+-------+------+---------+---------+---------+
  | 1  |   30   |  08   | 2015 |   12    |    5    |    2    |
  | 2  |   35   |  08   | 2015 |   12    |    5    |    2    |
  | 3  |   52   |  08   | 2015 |   12    |    5    |    2    |
  | 4  |   53   |  08   | 2015 |   12    |    5    |    2    |
  | 5  |   54   |  08   | 2015 |   12    |    5    |    2    |
  | 6  |   55   |  08   | 2015 |   12    |    5    |    2    |
  | 7  |   30   |  09   | 2015 |   12    |    3    |    0    |
  | 8  |   35   |  09   | 2015 |   12    |    3    |    0    |
  | 9  |   52   |  09   | 2015 |   12    |    2    |    1    |
  | 10 |   53   |  09   | 2015 |   12    |    3    |    0    |
  | 11 |   54   |  09   | 2015 |   12    |    3    |    0    |
  | 12 |   55   |  09   | 2015 |   12    |    3    |    0    |
  +----+--------+-------+------+---------+---------+---------+
  </code></pre>
  
  <p>I want to increment and decrement for each student <code>total_p</code> and <code>total_a</code>.</p>
  
  <p>when i am edit my student attendance list.</p>
  
  <blockquote>
    <p><strong>eg:</strong> studid 30 total_p = 5 and total_a= 2 ,so iam edit my attendance present become absent .</p>
  </blockquote>
  
  <p>so want decrement total_p by 1 and increment total_a by 1.</p>
  
  <p>So I'd like to get the total of each month for each <code>studid</code> and a increment and decrement of  <code>total_p</code> and <code>total_a</code> for the total months.</p>
  
  <p>My <strong>controller</strong> code is </p>
  
  <pre><code>
  foreach ($student as $student) {
              if ($present == 0) {
                  $query = DB::table($wys_total_attend_table)
                      -&gt;where('studid', $student-&gt;id)
                      -&gt;where('smonth', '=', $date_exploded[1])
                      -&gt;where('syear', '=', $date_exploded[2])
                      -&gt;update([
                          'stotal_p' =&gt; DB::raw('stotal_p - 1'),
                          'stotal_a' =&gt; DB::raw('stotal_a + 1'),
                      ]);
              } elseif ($present == 1) {
                  $query = DB::table($wys_total_attend_table)
                      -&gt;where('studid', $student-&gt;id)
                      -&gt;where('smonth', '=', $date_exploded[1])
                      -&gt;where('syear', '=', $date_exploded[2])
                      -&gt;update([
                          'stotal_p' =&gt; DB::raw('stotal_p + 1'),
                          'stotal_a' =&gt; DB::raw('stotal_a - 1'),
                      ]);
              }
          }
  
  </code></pre>
  
  <p>but it doesn't work..</p>
  
  <p>How to use <code>increment()</code> and <code>decrement()</code> in query builder format?</p>
  
  <blockquote>
    <p><strong>for eg:</strong>  if i only edit studid = 30 attendance increment total_p value 1 and (present == 1) studid = 30 total_p = 6 and total_a = 1 and other
    studid values are old value.</p>
  </blockquote>