arslan2037's avatar

Error in array in view file

I want to show data from array, but i have error and i am not able to find out why it gives me error, this is what i have in controller file, $json = file_get_contents($url);

                return view('store.show', compact('json'));

and this is in view file

    <?php 
    $leads = json_decode($json, true);

    $media = $leads['user']['media']['nodes'];

    dd($media);
    ?>

this code show data but when i try to show it using loop it gives me error

0 likes
15 replies
RamjithAp's avatar

Try this in your view

@foreach($json->user->media->nodes as $node)
{{$node->name}}
@endforeach
jestins's avatar
@if(isset($json['user']['media']['nodes']))
@foreach($json['user']['media']['nodes'])
{{$value = (isset($node['index']))?$node['index'] : ''}}
@endforeach 
@endif 

Try this.

arslan2037's avatar

it has syntax error i try to remove it but no success

bipin's avatar

@arslan2037 try this

        @foreach($json['user']['media'] as $node)
      
           //   {{$your required thing}}
        @endforeach
Robstar's avatar

@arslan2037 Please provide a full screenshot or paste of your json string. If you do this you'll get an answer much faster :)

Please or to participate in this conversation.