I suppose you have an unique index in table so if the same bid is to be saved (really a rare case) you'll get a PDO error that you can manage.
Lock tables in Eloquent / DB
I'm building an app where users can place bids on certain products in an auction. You always have to place a bid at least € 1,00 higher than the previous bid.
The PHP workflow:
- Fill form with bid
- Form request validates the bid (check if high enough)
- Eloquent save
- Redirect to auction page with succes or error notification.
Between step 2 and 3 there is a execution time gap of a few milliseconds. So in theory, users can place the same bid if they do it on exactly the same time. To prevent that, I have to lock the table before step 2 and release the lock after step 3.
So, my question is: Does anyone has any experience in locking tables (preferable in combination with Eloquent)? And how would you solve this?
N.B.: I haven't written any code for this (yet).
Please or to participate in this conversation.