Category: Laravel

I’ve recently found a simple package that helps to transform any URL into embeddable HTML, the best examples are Youtube and Vimeo videos.
Let’s imagine you have a video input text field (not uploadable video but URL), which you than need to transform into HTML code, depending on the platform.
Eloquent Accessor FieldLet’s attach the embedded HTML to an accessor field of app/Product.php model:use Cohensive\Embed\Facades\Embed; class Product extends Model { public function getVideoHtmlAttribute() { $embed = Embed::make($this->video)->parseUrl(); if (!$embed) return ''; $embed->setAttribute(['width' => 400]); return $embed->getHtml(); } }Step 4.
View Embedded HTMLIn the Blade code, you just need to view this:{!!
I haven’t tested, but the package has more support for embeddable platforms, see its configuration file:youtubePlaylistVideoyoutubePlaylistyoutubeliveleakvimeodailymotiongametrailersignvinecoubkickstarterustreamtwitchArchivetwitchArchiveChaptertwitchhtml5videogfycatweb.tv
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners