[英]Eloquent get all models associated with model X
我面臨的問題是,我希望特定季節的所有比賽都屬於該球員。 我將Slo 2與Eloquent結合使用。
這是我的ERD:
這有可能嗎? 我當時想從賽季開始,這樣我可以下降,但是我面臨一個問題,一場比賽可以有多名球員,我很想使用球員模型來稱呼他所有的比賽。
更容易-當您有season id
:
$player->matches()->whereHas('game', function ($q) use ($seasonId) {
$q->where('season_id', $seasonId);
})->get();
只是名字而已:
$player->matches()->whereHas('game.season', function ($q) use ($seasonName) {
$q->where('name', $seasonName);
})->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.