【发布时间】:2020-12-14 18:57:49
【问题描述】:
此代码现在获取所有匹配项。我只需要在 home_team_score 和 away_team_score 不为空的地方取:
$matches = Match::with('score', 'homeTeam', 'awayTeam')->
where('league_id', '=', $league->id)->get();
foreach ($matches as $match) {
$homeTeamScore = $match->score->home_team_score;
$awayTeamScore = $match->score->away_team_score;
在此处帮助了解 where 条件。
【问题讨论】:
-
您是否考虑过使用
whereHas来查询关系条件的存在? laravel.com/docs/8.x/…
标签: php arrays laravel model-view-controller eloquent