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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners