定制 bensampo/laravel-embed 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bensampo/laravel-embed

最新稳定版本:v3.0.0

Composer 安装命令:

composer require bensampo/laravel-embed

包简介

Painless responsive embeds for videos, slideshows and more.

README 文档

README

Laravel Embed

Effortless responsive embeds for videos, slideshows and more.
Created by Ben Sampson

Packagist Stable Version Packagist downloads MIT Software License

Requirements

  • Laravel 8 or newer
  • PHP 7.4.0 or newer

Installation

1. Composer

composer require bensampo/laravel-embed

2. Include styles

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.

3. Publish views (optional)

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/.

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.

<x-embed url="https://www.youtube.com/watch?v=oHg5SJYRHA0" />

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.

<x-embed url="https://www.youtube.com/watch?v=oHg5SJYRHA0" aspect-ratio="4:3" />

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.

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
            ])
        ],
    ]);
}

Embed Services

Laravel embed supports multiple popular embed services such as YouTube, Vimeo and Slideshare.

See the full list →

Please submit an issue (or better yet a PR!) if the service you'd like to embed is not listed.

统计信息

  • 总下载量: 122.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 140
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 140
  • Watchers: 6
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固