Package Data | |
---|---|
Maintainer Username: | BenSampo |
Package Create Date: | 2020-08-13 |
Package Last Update: | 2024-04-24 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:23:49 |
Package Statistics | |
---|---|
Total Downloads: | 74,924 |
Monthly Downloads: | 2,210 |
Daily Downloads: | 98 |
Total Stars: | 135 |
Total Watchers: | 6 |
Total Forks: | 19 |
Total Open Issues: | 2 |
8
or newer7.4.0
or newercomposer require bensampo/laravel-embed
Somewhere inside the <head>
element of the document, include:
<x-embed-styles />
If you'd prefer to include the styles in your own CSS file, you may copy the contents of styles.blade.php
.
If you'd like to edit any of the views you may publish them:
php artisan vendor:publish --provider="BenSampo\Embed\EmbedServiceProvider"
Once published they can be found in /resources/views/vendor/embed/
.
Simply include the following blade component in your view making sure to pass the url
attribute.
The url
should be the public URL for the page you're trying to embed.
<x-embed url="https://www.youtube.com/watch?v=oHg5SJYRHA0" />
By default most embedded services are shown at a ratio of 16:9
. Some services may override this if they have a more appropriate default. However, you can always change this by passing in a ratio to the aspect-ratio
attribute.
<x-embed url="https://www.youtube.com/watch?v=oHg5SJYRHA0" aspect-ratio="4:3" />
The aspect ratio is maintained at different viewport sizes.
If no service exists to handle the URL a fallback view is rendered. You can customize this by publishing the views and editing /resources/views/vendor/embed/services/fallback.blade.php
.
A validation rule can be used to check for a supported service in a given URL.
use BenSampo\Embed\Rules\EmbeddableUrl;
public function store(Request $request)
{
$this->validate($request, [
'url' => ['required', new EmbeddableUrl],
]);
}
You may specify a list of allowed services using the allowedServices
method.
use BenSampo\Embed\Services\Vimeo;
use BenSampo\Embed\Services\YouTube;
use BenSampo\Embed\Rules\EmbeddableUrl;
public function store(Request $request)
{
$this->validate($request, [
'url' => [
'required',
(new EmbeddableUrl)->allowedServices([
YouTube::class,
Vimeo::class
])
],
]);
}
Laravel embed supports multiple popular embed services such as YouTube, Vimeo and Slideshare.
Please submit an issue (or better yet a PR!) if the service you'd like to embed is not listed.