laravel blade视图模板

时间:2017-03-16 16:50:45

标签: php laravel laravel-5 templating laravel-blade

这是$reviewDetails

Array (
    [0] => stdClass Object (
        [userId] => 1
        [activityId] => 20
        [reviewId] => 6
        [title] => 
        [description] => 
        [rating] => 4
        [userName] => abcd
        [userCity] => wwqqwe
        [profilePicture] => 
        [reviewDate] => 2017-00-09 
        [images] => 
        [status] => 1
   )
   [1] => stdClass Object (
       [userId] => 78
       [activityId] => 20
       [reviewId] => 33
       [title] => Star trek
       [description] => nice trek
       [rating] => 4
       [userName] => abcd
       [userCity] => 
       [profilePicture] => MTQ4OTUwOTYzOS43OA==
       [reviewDate] => 2017-03-11 12:19:39
       [images] => Array (
           [0] => stdClass Object (
               [title] => my click
               [file] => MTQ4OTIzNDcwNy42OA==
           )
           [1] => stdClass Object (
               [title] => my click
               [file] => MTQ4OTIzNDczMi4xMQ==
           )
       )
       [status] => 0
    )
)

reviews.blade.php文件

@foreach ($reviewDetails as $reviewDetail)
    @if (! empty($reviewDetail->images))
        @foreach ($reviewDetail->images as $reviewImage)
            <p>
                <img src="{{ $reviewImage->file }}">
            </p>
        @endforeach
    @else
        <p>No image</p>
    @endif
@endforeach

此代码在laravel中不起作用,它显示尝试获取非对象的属性? 如何在刀片模板中显示图像阵列....请帮助

1 个答案:

答案 0 :(得分:1)

你在foreach循环中错过了一个$。此外,HTML中未关闭<img>标记。

@foreach($reviewDetails as $reviewDetail)
    @if(!empty($reviewDetail->images))
        @foreach($reviewDetail->images as $reviewImage)
            <p><img src="{{$reviewImage->file}}"></p>
        @endforeach
    @else
         <p>No image</p>
    @endif
@endforeach