且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 雄辩搜索领域相关模型

更新时间:2022-12-09 21:54:56

这就是 whereHas 派上用场的地方:

That's where whereHas comes in handy:

$user = User::with('Profile')->where('status', 1)->whereHas('Profile', function($q){
    $q->where('gender', 'Male');
})->get();

基本上它增加了用户需要具有gender = Male

Basically it adds the condition that the user needs to have a profile with gender = Male