如何在Laravel View Blade中显示数据库列中的Json编码数据

时间:2019-04-10 12:01:44

标签: php laravel

将图像位置网址存储到我的数据库列中,即图像。并且格式为…[“ http://kizflex.local/properties/10.jpg”,“ http://kizflex.local/properties/11.jpg”]

那么我如何遍历此特定列以获取每个地址并在我的视图中显示它?请卡住,我需要帮助。

@foreach($properties->all() as $property)
                   <h1>{{$property->property_title}}</h1>
                   @foreach (json_decode($property->property_image, true) as $image)
              <img src="{{ $image[0] }}" alt="" width="100%">


    @endforeach
@endforeach

2 个答案:

答案 0 :(得分:0)

@php $index=0; @endphp @for($i=0;$i < count($productDetails);$i++)
    <div class="row">           
        <div class="col-lg-3 col-md-4 col-xs-5 thumb">
            <a class="thumbnail"
                href="{{url('route')}}"
                style="box-shadow: 0px 1px 3px 3px #337ab724"> <img
                src="{{asset($productDetails[$i]['path'])}}"
                class="img-rounded">                    
            </a>
        </div>
    </div>
    @endfor

答案 1 :(得分:0)

您的数组只有一个级别,因此$image是一个字符串。您需要将{{ $image[0] }}替换为{{ $image }}

@foreach($properties->all() as $property)
    <h1>{{$property->property_title}}</h1>
    @foreach (json_decode($property->property_image, true) as $image)
        <img src="{{ $image }}" alt="" width="100%">
    @endforeach
@endforeach