相关文章推荐
率性的蚂蚁  ·  高合hiphi ...·  1 年前    · 
骑白马的菠萝  ·  腾讯视频·  1 年前    · 
八块腹肌的小熊猫  ·  Amazon.com·  1 年前    · 

laravel wherehas without global scope

在 Laravel 中,如果您想获取不包含全局作用域的模型,您可以使用 withoutGlobalScope 方法。

$users = User::withoutGlobalScope(ActiveScope::class)->get();

如果您使用的是 whereHas 方法,您可以结合 withoutGlobalScope 使用:

$users = User::withoutGlobalScope(ActiveScope::class)->whereHas('posts', function ($query) {
    $query->where('title', 'like', '%first%');
})->get();

这样,您就可以获取不包含全局作用域的模型了。

  •