Support the ongoing development of Laravel.io →
Database Eloquent Architecture

Hi,

I have a Controller that needs to process a form and then do some database checks that involve lockForUpdate on the Whatever table.. (I need to do some operations based on the count, so I can't allow concurrent count-select queries from different users)

The Service and the Model interact with the Database (say Service uses DB::raw and Repository/Model use Eloquent eg Whatever::count()

should I just DB::beginTransaction/lockForUpdate at the top of my controller, let the other service/model queries run as usual and then DB::commit at the end of my controller?

thanks J

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jmp909 jmp909 Joined 29 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.