Use Laravel without global scopes

6

If you want to explicitly avoid a global scope for a given query, you may use the withoutGlobalScope() method. The method accepts the class name of the global scope as its only argument.

$ingredient->withoutGlobalScope(LocaleScope::class)->touch();
$ingredient->withoutGlobalScopes()->touch();

Since you’re not calling touch() directly, in your case it will require a bit more to make it work.

You specify relationships that should be touched in model $touches attribute. Relationships return query builder objects. See where I’m going?

protected $touches = ['recipes'];
public function recipes() {
   return $this->belongsToMany(Recipe::class)->withoutGlobalScopes();
}

If that messes with the rest of your application, just create a new relationship specifically for touching (heh ?

protected $touches = ['recipesToTouch'];
public function recipes() {
   return $this->belongsToMany(Recipe::class);
}
public function recipesToTouch() {
   return $this->recipes()->withoutGlobalScopes();
}