title: Using insert with condition on laravel
body: <p>I want to insert value to 'ta' and 'tb'(int) column with some condition. I have this controller.</p>
  
  <pre><code>public function save()
  {
  $book = new Book;
  
  $ta = DB::select('SELECT MAX(ta) from book');
  if ($ta == 0) { 
          DB :: insert('insert into book (ta, tb) values (?, ?)', array(1, 1));
      }else{
          $tb = DB :: select('select max(tb) from book where ta = ?', array('$ta'));
          if ($tb &lt;= 20) {
              DB :: insert('insert into book (ta, tb) values (ta=?, tb=?)', array('$ta', '$tb' + 1));
          }else{
              DB :: insert('insert into book (ta, tb) values (ta=?, tb=?)', array('$ta' + 1, 1));
          }
      }
  $book-&gt;ta = $ta;
  $book-&gt;tb = $tb;
  $book-&gt;save();
  }
  </code></pre>
  
  <p>How can I resolve this?</p>