Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent and Query Builder "with (nolock)"

I have some throuble because my queries not have with (nolock) instruction after from clause.

Because that, some queries lock the database and then nobody can use the system.

How to use with (nolock) with Eloquent & Query Builder?

For example.. in this query:

return static::with('campaignType')
    ->where('active', 1)
    ->get();

I want the follow result:

select
    *
from campaigns with (nolock)
inner join campaign_types with (nolock) on campaign_types.id = campaigns.campaign_type_id 
where campaigns.active = 1 
like image 695
Patrick Maciel Avatar asked Oct 27 '25 21:10

Patrick Maciel


1 Answers

You can set "with(nolock)" like this:

DB::table('campaigns')->lock('WITH(NOLOCK)')
like image 155
Tola Avatar answered Oct 29 '25 11:10

Tola