Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5 获取视图上的相关对象_Laravel 5_Laravel 5.8 - Fatal编程技术网

Laravel 5 获取视图上的相关对象

Laravel 5 获取视图上的相关对象,laravel-5,laravel-5.8,Laravel 5,Laravel 5.8,我有相关的模型 class Myevent extends Model { public function photo() { return $this->hasMany('App\EventPhoto'); } } Ob刀片如果循环我得到项目Myevents @foreach($evetns as $event) <b>{{$event->name}}</b> <br>

我有相关的模型


class Myevent extends Model
{
    public function photo()
    {
        return $this->hasMany('App\EventPhoto');
    }
}

Ob刀片如果循环我得到项目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
@foreach($evetns as$event)
{{$event->name}}
{{$event->place}}
{{$event->description}}
@foreach($event->photo()作为$item) {{$item->id} @endforeach @endforeach

如何在blade上调用循环中的相关对象?

除了一个错误
$event->photo
而不是
$event->photo()


为了消除关于括号的混淆

您可能有一种类型:
events
应该是
events
@KarlHill-请不要修复代码中的拼写错误,因为这可能是导致错误的原因problem@DerekPollard不,它不会,将抛出错误,请使用您自己的模型和关系在刀片中尝试打印($model->method()),为我抛出错误,
允许内存大小为134217728字节(尝试分配65015808字节)
使用
print\r($model->method())
我得到了这个,而使用
print\r($model->method())
,我得到了这个@derePollard。
@foreach($event->photo as $item)
    {{$item->id}}
@endforeach