0

Am storing the image location url to my database column called images. and the are in this form… [“http://kizflex.local/properties/10.jpg”,”http://kizflex.local/properties/11.jpg”]

So how can i iterate through this particular column so as to get each address and display it in my view? Please am stuck i need help.

@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
  • 1
    Do you get an error? If so can you share it? If not can you explain what you get now? – Techno Apr 10 '19 at 12:05
  • you could use JSON -> array mutator as found here https://laravel.com/docs/5.8/eloquent-mutators#attribute-casting – Vlad Visinescu Apr 10 '19 at 12:11
  • Possible duplicate of [Select value from JSON inside Laravel Blade](https://stackoverflow.com/questions/43881258/select-value-from-json-inside-laravel-blade) – akbansa Apr 10 '19 at 12:35

2 Answers2

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
Rahul Baraiya
  • 73
  • 1
  • 10
0

Your array only has one level, so $image is a string. You need to replace {{ $image[0] }} with {{ $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
Thomas
  • 8,426
  • 1
  • 25
  • 49