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

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

Community Partners