You could maybe use something like this.
Db::raw('lock tables mytable write'):
doYourStuff();
Db:raw('unlock tables');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
That's the question :-)
I realise rows can be locked when selecting, by using the lockForUpdate() method in an eloquent query. But what about a whole table?
We have a table that gets updated from a CSV file at regular times, and simply want to lock the table while doing the updates, just in case multiple update processes get run at the same time. The locks will force them to line up and take their turn. The updates are done in a single transaction, so an update process will update the whole table, or none of the table.
Now, we will be deploying to both MySQL and Azure SQL databases. The transaction handling and row locks of eloquent work brilliantly on both databases - the whole process is abstracted so it just works.
But whole table locks? Can't find any documentation on that. Anyone done this? Do I just need to manually check the database type then issue a raw DML table lock command appropriate to the RDBMS? Or does eloquent hold my hand and abstract it? Maybe there is an extension to eloquent that adds this feature?
Please or to participate in this conversation.