0

I'm building a social network site with Laravel

I have a section of my site where a user can submit a URL to a video with a form ex. https://www.youtube.com/watch?v=xxxxxxxxxx

The URL gets saved in the database.

I want to embed the youtube/vimeo player on the page using an iframe.

I can grab the url using $video->url

In order to display the iframe I use

<iframe width="306" height="200" src={{ $video->url }} frameborder="0" allowfullscreen></iframe>

The space is there but no video. Just blank space. I figure this is because the link is not the embed link youtube provides which should be //www.youtube.com/embed/xxxxxxxxxx

Is there a Laravel way to convert site URLs to embed URLs? I don't want to make my users submit the embed URL since most people don't know about it and it's easier for them to just submit the URL in their browser

xslibx
  • 4,249
  • 9
  • 35
  • 52

1 Answers1

3

You can grab the id of youtube video before saving the url to the database.

Then store the embed link:

"http://www.youtube.com/embed/$youtube_id"
Community
  • 1
  • 1
Pantelis Peslis
  • 14,930
  • 5
  • 44
  • 45