How to embed YouTube videos in Laravel: The easy way
I released a package recently which makes embedding YouTube videos incredibly simple: laravel-embed.
Once it's installed, you simply make use of the included x-embed
blade component passing the URL of the video in the url
attribute:
<x-embed url="https://www.youtube.com/watch?v=oHg5SJYRHA0" />
This will render the video in an iFrame. It's responsive out of the box and isn't just limited to YouTube - it also supports Vimeo and a selection of other services.
That's it. Dead simple.
laravel-embed has a bunch of other features too, such as validation rules and being able to set the aspect ratio. See the project docs