With match in laravel 4

I have searched online for a method to solve a match in Laravel 4, for example when you need to lock an entire table or just a row to update or create, but little information. On the laravel website, they mentioned two methods:

lockForUpdate()
sharedLock()

      

But when I use them, it has no effect. The way I use it is as follows:

Check if something exists in the table

Model::queryFunction()->lockForUpdate()->first();

      

If it doesn't exist, create a new item

$new_item = new Model;
$new_item->save();

      

Otherwise, don't do anything

If two users perform the same action at the same time, two items are created, and this is not the case. Hope you guys can answer my question.

+3


source to share





All Articles