How to use Youtube Class on View

316 views Asked by At

I am using Youtube package

I added this on app.php

Alaouy\Youtube\YoutubeServiceProvider::class,

&

'Youtube' => Alaouy\Youtube\Facades\Youtube::class,

now i m trying in view like this

{{ Youtube::getVideoInfo('rie-hPVJ7Sw') }}

but getting error

"htmlspecialchars() expects parameter 1 to be string, object given
(View: C:\xampp\htdocs\guru\resources\views\admin\video\index.blade.php)"

how can I fix this?

i Tried

@foreach($videos as $video)
  {{ var_dump(Youtube::getVideoInfo($video->videoid)) }}
@endforeach

its showing me everything
Here is Screenshot enter image description here

1

There are 1 answers

13
linktoahref On BEST ANSWER

As per the docs,

// Return an STD PHP object
$video = Youtube::getVideoInfo('rie-hPVJ7Sw');

so you could do,

{{ var_dump(Youtube::getVideoInfo('rie-hPVJ7Sw')) }}

to print out the object or assign it to a variable and access the respective object properties

EDIT

To show only the embed html you could use the following code

@foreach($videos as $video)
  {!! Youtube::getVideoInfo($video->videoid)->player->embedHtml !!}
@endforeach