Create a Dynamic Livewire Embed Component

Tony Xhepa| 00:07:38|Apr 20, 2026
Chapters6
Intro and setup showing how to sign up, access the embed page, and paste URLs to preview embeds for YouTube, Vimeo, and Spotify.

Tony Xhepa demonstrates a Laravel Livewire embed component that previews YouTube, Vimeo, and Spotify URLs with a single input and dynamic iframe rendering.

Summary

Tony Xhepa shows off a practical feature built with Laravel and Livewire: a dynamic embed component that turns a simple URL into a live preview. After signing in, you can navigate to /embed, paste a video or track URL, and immediately see a preview. He demonstrates with YouTube, Vimeo (Vmail in the transcript), and Spotify links, noting that full URLs are accepted and the component extracts the necessary embed URL to render an iframe. The code flow starts with a route and a Livewire component handling URL validation (using a custom EmbedableURL rule) and an embed manager that resolves the correct provider. The Embed component passes the URL to the embed blade, which then renders an iframe with a provider name and an aspect-ratio-specific container. Tony walks through the provider classes (YouTube, Vimeo, Spotify) and shows how each provider detects a matching URL and returns a provider-specific embed URL, aspect ratio, and name. The result is a reusable, extendable embed feature that can be expanded to support more services by adding new provider classes. This video is a concise, code-first walkthrough suitable for Laravel developers looking to add a plug-and-play embed capability to their apps.

Key Takeaways

  • Enter a URL on /embed to generate a live preview of the content (YouTube, Vimeo/Vmail, Spotify).
  • An Embedable URL validation rule ensures only supported URLs are accepted before rendering.
  • A central EmbedManager resolves the correct provider class for a given URL and returns an embed URL.
  • Each provider (YouTube, Vimeo, Spotify) implements detect() and embed URL() logic to produce a provider-specific iframe source.
  • The embed blade component renders a responsive iframe using an aspect-ratio container, producing clean, embed-friendly markup.
  • The codebase is designed to be easily extended by adding new provider classes without changing the core embedding flow.
  • This pattern provides a reusable, Laravel-friendly way to embed external media across pages or components.

Who Is This For?

Laravel developers who want a quick, reusable way to embed external media (YouTube, Vimeo, Spotify) via Livewire. Ideal for teams building content-rich dashboards or pages that require dynamic previews from a single URL input.

Notable Quotes

"paste the URL here and it's going to preview."
Shows the core UX: a single input drives the preview feature.
"it's going to preview the file from Vimeo."
Demonstrates handling of a Vimeo URL in the preview flow.
"Now we have the YouTube video. This is with the full URL."
Highlights that full URLs are accepted and rendered.
"embed manager which is I'm going to show you"
References the central component that resolves the correct provider.
"the embed blade Livewire component which we have here"
Points to the rendering path that outputs the iframe.

Questions This Video Answers

  • how do I implement a dynamic embed component with Laravel Livewire?
  • what is an EmbedManager pattern in Laravel and how does it resolve providers?
  • how can I add more providers (like TikTok or SoundCloud) to a Laravel embed system?
LaravelLaravel LivewireYouTube embedVimeo embedSpotify embedEmbedable URLEmbedManagerProvider patternPHPWeb components
Full Transcript
Hello friends, Tony here. Welcome. In today's video, I'm going to demo you another project I created with the cloud code and this is not a project. I just created one feature which is the embed component and is with Laravel and Lewire. So I'm going to sign up first and then if I if I navigate / embed I have created an URL for this. Now if we want to embed we just paste the URL here and it's going to preview. So enter a URL above and the preview an embed and support that is YouTube Vmail and Spotify. And for example I have open here the Vmail. I'm going to copy just the URL here. We can come here and paste that URL and say preview. And yeah, it's going to preview the file from Vimeo. As you can see, also if I go to YouTube and just copy this one. Come here. Replace now with the YouTube. Click the preview. Now we have the YouTube video. This is with the full URL. So YouTube come watch. If I refresh uh and just come here, I'm going to copy the video URL and then paste it right here. Now we have YouTube slash and ID. And if I say preview, the same thing is going to preview this this one. Also for the Spotify, if you go to Spotify, I'm going to copy for example. Let's copy this. Copy link the song and come here. paste that in. Click the preview and it's going to preview this one. So can preview. Okay. Now let's show you the code which I come here. I'm going to open first the web routes and we have the route live wire embed pages embed here and you can find also in the views pages embed.php. Here we have a class and HTML. Now let's see the class. First we have a string URL and then preview URL and then the preview method. First, it's going to validate the URL to be required URL and new embedable URL which is in the app rules embedable URL and it's going to work with this embed manager which is I'm going to show you but it's going to check if not embed app embed manager class supports passing the value is going to fail the attribute must be supported embed URL like YouTube, Vimeo or Spotify. Okay. So let's go again to embed plate and it's going to validate. Then it's going to say this preview URL to be as this URL here and computed supported providers returning the an array with We have the PL setting and text embed preview. Paste uh YouTube Vmail Spotify URL to preview. It's embed. And then we have a form with the input. So this is a form and a flux button to type submit and or submit preview. So it's going to call this method. Then we're going to show the error for the URL if we don't have a URL. So let's just say remove this preview. And yeah, we have the error. Then it's going to check if we have a preview URL. It's going to paste this live wire embed component which we have here. Pass in the URL and also the wire key. Now let's open this embed blade liveware component public string here we have public string URL and then provider if empty this URL is going to return null otherwise going to return app embed using that embed manager resolve pass in this URL and then if this provider is going to add a div with style aspect ratio and then the i frame with source of this provider embed URL class allow full screen allow autoplay loading lazy and title this provider name as if the URL is going to say once imported embed URL okay now let's see up here we have the in the app we have the embed and then we have embed manager what we saw earlier and we have this resolve and also support resolve is going to receive the URL which is a string and then it's going to return the provider said to make for each this providers as provider class because here we have a protected providers which is an array with YouTube class vmail and Spotify I'm going to show you right now and it's going to make for each these providers as provider class and if provider class detect passing the URL we have here is going to return new provider class in the URL otherwise it's going to return null and also supports is going to receive the URL and it's going to return a boolean and say this resolve pass in the URL is not able to null now let's open the YouTube vimeo and Spotify and here we have providers Spotify provider we detect method receiving the URL and is going to return boolean pretty much openspotify.com and that URL pretty much match open Spotify comb episode show type and id and then it's going to return https open Spotify com/bed slash the type slash the id aspect ratio 4x1 and name Spotify then we have the Vmail provider private read only string URL detect receiving the URL and pragmasvmail.com URL embed URL pragmatv com video this URL matches and playervo.com/vide/ matches one or an empty string aspect ratio six 16 by9 and name vmail then we have a YouTube the same We have also the constructs provider and here we have public function embed URL aspect ratio and name. Okay. So embed URL aspect ratio and the name. Okay friends this is all about this video what I wanted to show you an embed component with liveware and Laravel which can work with YouTube vmail and Spotify but yeah you can add more if you like. Now, if you like such a videos, don't forget to subscribe to my channel, like the video, share with your friends, and I'm going to see you in another one. All the best, and thank you very much.

Get daily recaps from
Tony Xhepa

AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.