Pessimistic Locking in Laravel 5

Shared lock is, when more than one transaction is granted read access to a given record. One transaction gets shared lock on a record.

DB::table('tbl_order')->where('amount', '>', 100)->sharedLock()->get();

lockForUpdate

You can use it, when reading to prevent the rows from being modified or from being selected with another shared lock. Or you can lock some row(s) until your transaction finishes updating.

DB::table('tbl_order')->where('amount', '>', 100)->lockForUpdate()->get();

http://web.archive.org/web/20201201154548if_/https://www.facebook.com/plugins/like.php?href=https://scripts.guru/pessimistic-locking-in-laravel-5/&layout=button_count&show_faces=false&width=105&action=like&colorscheme=light&height=21

Leave a Reply

Your email address will not be published. Required fields are marked *