我有两个类别,分别命名为academy和pitch,球场可以有多个学院,而acdemy属于一个球场,在学院的显示视图中,我可以使用以下命令查看球场名称
{{$academy->pitch->name}}但是反过来它不起作用,我的意思是我想在每个投球中列出学院的名字。
我的模型
学院模式
public function pitch(){
return $this->belongsTo(Pitch::class ,'pitch_id');
}音高模型
public function academies()
{
return $this->hasMany(Academy::class);
}我试过了,但不起作用
@foreach ($pitch->academies as $academy)
<li></li>
@endforeach错误
Column not found: 1054 Unknown column 'academies.pitch_pitch_id' in 'where clause' (SQL: select * from `academies` where `academies`.`pitch_pitch_id` = 5 and `academies`.`pitch_pitch_id` is not null)发布于 2020-06-03 06:28:13
public function academies()
{
return $this->hasMany(Academy::class, 'academy_id');
}
public function pitch(){
return $this->belongsTo(Pitch::class ,'pitch_id');
}在我看来
@foreach ($pitch->academies as $academy)
{{$academy->name}}
@endforeach我现在工作了
https://stackoverflow.com/questions/62161838
复制相似问题