0

I saw most of examples in Pessimistic locking by using query builder, like in below.

DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get();

How can I use Pessimistic locking with Eloquent in laravel?

mega6382
  • 9,211
  • 17
  • 48
  • 69
Udara Herath
  • 805
  • 2
  • 18
  • 37
  • use transaction.. well, you can dig in stackoverflow for examples.. and no, i'm not the one downvote you.. – Bagus Tesa Oct 23 '17 at 09:56
  • Did you test it with eloquent `User::where('votes', '>', 100)->lockForUpdate()->get();` what did you get ?? – Maraboc Oct 23 '17 at 10:22

1 Answers1

0

To do this you simply need to use the model as normal. As stated in Maraboc's comment just use the Eloquent model and set filters and call lockForUpdate before the get().

Example: User::where('votes', '>', 100)->lockForUpdate()->get();

Bill Garrison
  • 2,226
  • 3
  • 34
  • 75