提问者:小点点

Laravel 5.8在刀片中显示数据


我使用espresso-dev/instagram-basic-display-php包,想显示instagram帖子。 到目前为止,我创建了controller:

use EspressoDev\InstagramBasicDisplay\InstagramBasicDisplay;


class PagesController extends Controller
{



public function index(){

    $categories = Category::all();
    $bigPosts = Post::where('featured', 1)->latest()->take(3)->get();
    $posts = Post::where('featured', 0)->paginate(20);
    $instagram = new InstagramBasicDisplay('My-generated-basic-display-api-token');
    $profile = $instagram->getUserMedia('me', 4);

    return view('index', [

      'categories' => $categories,
       'bigPosts' => $bigPosts,
        'posts' => $posts,
        'profile' => $profile
    ]);
}

在dd('$profile')上,我获取此信息:

array:4 [▼
  0 => {#819 ▼
    +"id": "17952224896339501"
    +"media_type": "IMAGE"
    +"media_url": "https://scontent.cdninstagram.com/v/t51.2885-15/103084696_202267110897249_560860048394897443_n.jpg?_nc_cat=108&_nc_sid=8ae9d6&_nc_ohc=TkOxBfDB6BwAX-v2p82&_nc_ht ▶"
    +"permalink": "https://www.instagram.com/p/CBTPAtepU5e/"
    +"timestamp": "2020-06-11T15:53:36+0000"
    +"username": "house4hair.nails.beauty"
  }
  1 => {#818 ▶}
  2 => {#806 ▶}
  3 => {#792 ▶}
]

如何在刀片中显示这些信息?


共2个答案

匿名用户

您可以通过在刀片组件中循环数组来访问提要内容。

@foreach($profile as $feed)
<h1>{{ $feed->username }}</h1>
<img src="{{ $feed->media_url }}">
@endforeach

匿名用户

假设您要访问第一个数组中的信息

$profile[0]->$item_to_access 

例如,要访问媒体类型,可以使用$profile[0]->media_type

但是,如果您想再次访问每个项,例如您想访问media_type,那么您将在刀片中使用foreach语句。

@foreach($profile as $p)
   Media Type: {{$p->media_type}}
@endforeach