Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bensampo/laravel-embed
Effortless responsive embeds for videos, slideshows and more.
https://github.com/bensampo/laravel-embed
embed laravel laravel-package vimeo youtube
Last synced: 23 days ago
JSON representation
Effortless responsive embeds for videos, slideshows and more.
- Host: GitHub
- URL: https://github.com/bensampo/laravel-embed
- Owner: BenSampo
- License: mit
- Created: 2020-08-13T16:54:33.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-24T15:11:26.000Z (7 months ago)
- Last Synced: 2024-09-19T11:42:15.481Z (about 2 months ago)
- Topics: embed, laravel, laravel-package, vimeo, youtube
- Language: PHP
- Homepage:
- Size: 1.15 MB
- Stars: 134
- Watchers: 5
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Embed
Effortless responsive embeds for videos, slideshows and more.
Created by Ben Sampson## Requirements
- Laravel `8` or newer
- PHP `7.4.0` or newer## Installation
### 1. Composer
```bash
composer require bensampo/laravel-embed
```### 2. Include styles
Somewhere inside the `` element of the document, include:
```html
```
If you'd prefer to include the styles in your own CSS file, you may copy the contents of [`styles.blade.php`](https://github.com/BenSampo/laravel-embed/blob/master/resources/views/components/styles.blade.php).
### 3. Publish views (optional)
If you'd like to edit any of the views you may publish them:
```bash
php artisan vendor:publish --provider="BenSampo\Embed\EmbedServiceProvider"
```Once published they can be found in `/resources/views/vendor/embed/`.
## Usage
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.
```html
```
### Setting the aspect ratio
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.
```html
```
The aspect ratio is maintained at different viewport sizes.
### Fallback
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`.
### Validation
A validation rule can be used to check for a supported service in a given URL.
```php
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.
```php
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
])
],
]);
}
```## Embed Services
Laravel embed supports multiple popular embed services such as YouTube, Vimeo and Slideshare.
[See the full list →](https://github.com/BenSampo/laravel-embed/tree/master/src/Services)
Please submit an issue (or better yet a PR!) if the service you'd like to embed is not listed.