0

I have successfully fetched two items from an API but when displaying on my view, only one item is showing on my view. What could i be doing wrong in my code below ?

When i echo results, i am able to see that two items are being returned although just one is displayed on the view.

PS: Beginner in Laravel & PHP

Controller

    public function fetch()
    {
            $response = $client->request('/users/99979100/videos', array(), 'GET');
            $results =  json_decode(json_encode($response),true);
            $export_details = $results;
            return view('home',compact('export_details'));
}

View

  <div class="video-title">
  <a href="#">{{$export_details['body']['data'][0]['name']}} - {{$export_details['body']['data'][0]['description']}} </a>
  </div>
1
  • What do you expect? You're only echoing one row. Try using a loop on $export_details Commented Aug 15, 2019 at 15:29

2 Answers 2

1

You have to loop through your results...

@foreach($export_details['body']['data'] as $export_detail)
    <a href="#">{{$export_detail['name']}} - {{$export_detail['description']}} </a>
@endforeach
Sign up to request clarification or add additional context in comments.

Comments

1

You need to loop through your array which you are returning to your view, I am not sure what exactly your array contains but you should be able to do something like this in your blade file:

@foreach($export_details as $exportKey => $exportValue)
    <p>{{ $exportValue }}</p>
@endforeach

If you array contains multiple array you need to create multiple loop in your foreach. Check out the docs for more information.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.