我正在使用Laravel 5.7。我有一个“匹配”模型,其第一个参与者名称是从帮助函数getFirstParticipant(Match $ match)返回的。 我正在尝试从DB的某些参与者中获取某些匹配项,例如'约翰'。我是否有可能使用雄辩的查询功能来做到这一点?
Match::where('firstParticipant','John')
或任何其他解决方案?
如果要帮助您声明问题,我在下面复制我的辅助函数:
function getFirstParticipant(Match $match)
{
$structure_id = $match->structure_id;
$seed = $match->matchResult->first_seed;
$placement = Placement::where('structure_id',$structure_id)->where('seed',$seed)->first();
return !empty($placement->player_id) ? $placement->player->username : $placement->team->name;
}