laravel 关系列在哪里等于?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43105870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:40:56  来源:igfitidea点击:

Where relationship column equals?

phpmysqllaravelshoes

提问by VoiD HD

I am trying to grab all records where Player's relationship called stats()has a column value of something. I would usually do ::where('column_name' 'column_value')for the players table, but how can I get ::where the relationship table's column equals to something?

我正在尝试获取所有记录,其中调用的玩家关系stats()具有某个列值。我通常会::where('column_name' 'column_value')为玩家表做,但我怎么能得到 :: 关系表的列等于什么?

Player::where('column_name', 'column_value')->get();

But I want to check a column in the relationships table?

但我想检查关系表中的一列?

public function roleplay()
{
    return $this->hasOne('App\Database\Frontend\User\Roleplay', 'user_id', 'id');
}

回答by oseintow

This will filter Player based on a related table

这将根据相关表过滤播放器

Player::whereHas('roleplay', function($q){
   $q->where('column_name', 'value');
})->get();