Tuesday, September 24, 2019

PHP Laravel Lock For Update with Eloquent



public function lockForUpdate()
    {
     \DB::transaction(function () {
      $update = JasperReportParam::where('ID','=', 26262)->lockForUpdate()->first();
      $update->ID = 26262;
      $update->status   = 'LOCK';
      $update->save();
     });
    }
* The selected row will be locked from being selected or updated by other process. This will solve race condition issue in updating the same record.

No comments:

Post a Comment