【发布时间】:2017-03-22 23:35:26
【问题描述】:
在 Laravel 5.4 方面需要帮助。
我有两张桌子:origins 和 coffees。
一个产地可以有很多咖啡。
在我设置的 Origin 模型中:
public function coffee()
{
return $this->hasMany('App\Coffee');
}
在我的控制器中,我有这个:
$origins = Origin::with('coffee')->get();
在我看来,我需要显示每个产地的所有咖啡,我的代码:
@foreach($origins as $origin)
<div class="row">
<div class="col-lg-12 centered">
<h3>{{ $origin->name }}</h3>
@foreach($origin->coffee() as $coffee)
{{ $coffee->name }}
@endforeach
</div>
</div>
@endforeach
但是没有显示咖啡名称。
我在咖啡桌中有一条记录属于 id 为 1 的来源。
为什么我不知道咖啡的名字?
谢谢
【问题讨论】: