我有相关模型
class Myevent extends Model
{
public function photo()
{
return $this->hasMany('App\EventPhoto');
}
}
如果循环,我将获得Myevents项目
@foreach($evetns as $event)
<b>{{$event->name}}</b> <br>
{{$event->place}} <br>
{{$event->description}} <br>
@foreach($event->photo() as $item)
{{$item->id}}
@endforeach
@endforeach
如何在刀片循环中调用相关对象?
答案 0 :(得分:1)
您似乎做得正确,但只有一个错误$event->photo
而不是$event->photo()
@foreach($event->photo as $item)
{{$item->id}}
@endforeach
要消除有关方括号https://laraveldaily.com/calling-eloquent-from-blade-6-tips-for-performance/的困惑