【发布时间】:2023-03-15 11:45:02
【问题描述】:
这是我的控制器:
$homeTeamFacts = DB::table('match_facts')
->where('match_id', $match->id)
->join('players', 'match_facts.player_id', '=', 'players.id')
->where('players.team_id', '=', $homeTeamId)
->get();
这是我得到的数据收集:
Illuminate\Support\Collection {#1311 ▼
#items: array:4 [▼
0 => {#1325 ▼
+"id": 2
+"match_id": "1"
+"player_id": "2"
+"minutes": 90
+"goals": null
+"yellowCard": 1
+"redCard": 0
+"bench": 0
+"created_at": "2021-01-08 11:12:59"
+"updated_at": "2021-01-08 11:12:59"
+"team_id": "1"
+"position": "Gynėjas"
+"photo": null
+"name": "Tomas"
+"surname": "Tomaitis"
+"birth_date": null
+"city": null
+"height": null
+"weight": null
}
1 => {#1332 ▶}
2 => {#1323 ▶}
3 => {#1333 ▶}
]
}
问题是当我尝试使用“{{$fact -> player-> name}}”查看玩家姓名时
当我收到这样的错误“未定义的属性:stdClass::$player(查看:.....”
但是当我得到这样的数据时:
$MatchFacts = Match_fact::where('match_id', $match->id)
->get();
没有问题,而且关系很好。 是否有任何选项可以使关系对我提到的问题起作用?
【问题讨论】:
标签: arrays database laravel model-view-controller eloquent