Laravel:如何在Eloquent中使用悲观锁定? [英] Laravel: How to use pessimistic locking with Eloquent?
本文介绍了Laravel:如何在Eloquent中使用悲观锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过使用查询生成器看到了悲观锁定中的大多数示例,如下所示.
I saw most of examples in Pessimistic locking by using query builder, like in below.
DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get();
我如何在laravel中对Eloquent使用悲观锁定?
How can I use Pessimistic locking with Eloquent in laravel?
推荐答案
要执行此操作,您只需正常使用模型即可.如Maraboc的评论所述,仅使用Eloquent模型并设置过滤器,并在get()之前调用lockForUpdate.
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().
示例:User::where('votes', '>', 100)->lockForUpdate()->get();
这篇关于Laravel:如何在Eloquent中使用悲观锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文