Laravel/PHP Articles

Articles from Laravel/PHP sites on the web

Laravel/PHP Articles
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

Sign Up For Our Newsletter

Each Week, We curate the top Laravel/PHP articles, jobs, events and More!

We'll send you a weekly email with the latest Laravel/PHP articles, jobs and events. Please review our Code of Conduct in the meantime. Talk to you soon!