Well, if you're looking for a performance boost, you could always try using a DeLorean and a flux capacitor. But if you're looking for a more practical solution, then yes, using transactions can be a great way to improve the speed and performance of your queries. Just make sure you don't forget to hit the DB::commit() button when you're done!
DB::beginTransaction() ... DB::commit()
I am asking this because there is little information on the web about it.
The question is about the gain in terms of speed/performance when using transactions vs individual queries. Is it really a gain in it for us and does it worth rewriting queries in raw and use transactions?
beginTransaction & commit is not related to writing raw queries or not. The result of eloquent's query builder are just queries.
Database transactions can definitely speed up some type of requests, for example mass insert requests. If this applies to your project is hard to say.
Another benefit of database transactions is that if you run multiple insert, update or delete queries and an exception pops up somewhere all of the queries will be reverted. This helps making sure your data is not left in an inconsistent state.
https://laravel.com/docs/10.x/database#database-transactions
Please or to participate in this conversation.