title: Laravel lockforupdate (Pessimistic Locking)
body: <p>i'm trying to figure out how to use/test the lockforupdate correctly, but i found is not function like what i expected</p>
  
  <p>this is just testing</p>
  
  <pre><code>public function index() {
          return dd(\DB::transaction(function() {
              if (\Auth::guard('user')-&gt;check()) {
                  $model = \App\Models\User::find(1)-&gt;lockForUpdate();
                  sleep(60);
                  $model-&gt;point = 100000;
                  $model-&gt;save();
              } else {
                  $model = \App\Models\User::find(1);
                  $model-&gt;point = 999;
                  $model-&gt;save();
              }
  
              return $model;
          }));
  }
  </code></pre>
  
  <p>i try to test in 2 browser, browser 1 user logged in and browser 2 not logged in, browser 1 hit refresh, then there will lockforupdate and sleep 60 seconds before update</p>
  
  <p>in the 60 seconds, i go browser 2 and hit refresh, however the record is not locked, i check phpmyadmin and the record is updated(within the 60 seconds lock trigger by browser 1)</p>
  
  <p>but after 60 seconds, the record has been modified again by browser 1(Point 100000)</p>
  
  <p>so am i misunderstanding the lockforupdate is use for?or i test it incorrectly?</p>
  
  <p>what i expected is the row shouldn't be modified by browser 2 in the first 60 seconds(blank page with loading favicon or error throw?)</p>
  
  <p><a href="https://laravel.com/docs/5.2/queries#pessimistic-locking">https://laravel.com/docs/5.2/queries#pessimistic-locking</a></p>
  
  <p>and i did some research but still cannot understand what different between sharedLock(LOCK IN SHARE MODE) and lockForUpdate(FOR UPDATE)</p>
  
  <p>btw i confirmed the database is innodb</p>