简体   繁体   English

在刀片视图中显示阵列数据-Laravel

[英]Displaying array data in blade view - Laravel

I have successfully fetched two items from an API but when displaying on my view, only one item is showing on my view. 我已经成功地从API提取了两项,但是在视图上显示时,视图上仅显示一项。 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. 当我回显results ,尽管视图中仅显示一项,但我能够看到返回了两项。

PS: Beginner in Laravel & PHP PS: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>

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. 如果数组包含多个数组,则需要在foreach中创建多个循环。 Check out the docs for more information. 查看文档以获取更多信息。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM