i\'m trying to figure out how to use/test the lockforupdate correctly, but i found is not function like what i expected
this is just testing
public f
SharedLock:
DB::table('users')->where('votes', '>', 100)->sharedLock()->get();
LockForUpdate:
DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get();
Laravel Docs
This work, finally, but still don't understand what sharedLock(LOCK IN SHARE MODE) and lockForUpdate(FOR UPDATE) different
public function index() {
return dd(\DB::transaction(function() {
if (\Auth::guard('user')->check()) {
$model = \App\Models\User::lockForUpdate()->find(1);
sleep(30);
$model->point = 100000;
$model->save();
} else {
$model = \App\Models\User::lockForUpdate()->find(1);
$model->point = $model->point + 1;
$model->save();
}
return $model;
}));
}