title: dealing with concurrence in laravel 4
body: <p>I've been searching on the internet for a method to deal with concurrence in Laravel 4, like for example when you have to block the entire table or just a row for updating or creating but found little information. On the laravel website they mentioned two methods:</p>
  
  <pre><code>lockForUpdate()
  sharedLock()
  </code></pre>
  
  <p>But when I use them, it has no effects. The way I'm using it is as follows:</p>
  
  <p>Check if something exist on the table</p>
  
  <pre><code>Model::queryFunction()-&gt;lockForUpdate()-&gt;first();
  </code></pre>
  
  <p>If not exist, create a new item</p>
  
  <pre><code>$new_item = new Model;
  $new_item-&gt;save();
  </code></pre>
  
  <p>Else, do nothing</p>
  
  <p>If two users do the same action at the same time, two items are created, and that's not right. I hope you guys can answer my question.</p>