mpratt/embera
Embera is a PHP library for turning URLs into rich embeds via oEmbed. It supports many providers, offers easy integration, caching, and flexible configuration, making it simple to render videos, tweets, and other media in your apps.
composer require mpratt/embera.$embera = new \Embera\Embera(['discover' => true]);
$response = $embera->getUrlEmbedData('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo $response->html; // Outputs the embed <iframe> or <blockquote>
Start with basic usage and enable discover (auto-detect oEmbed endpoints) for maximum compatibility. Use the getDefaultConfig() method to inspect available options.
@component or helper function (e.g., oembed('https://...')) for clean view usage:
{!! oembed($videoUrl) !!}
$cacheKey = 'embera_' . md5($url);
$embed = Cache::remember($cacheKey, now()->addDay(), fn() => $embera->getUrlEmbedData($url));
responsive config option to automatically wrap <iframe> in responsive containers (div AspectRatio).discover to false and pre-register providers (e.g., Youtube, Vimeo) for reliable local rendering without network dependency.?cc_load_policy=1&iv_load_policy=3 to 参数).$response->html before output in Blade using {!! !!} only after confirming trust (oEmbed responses can include arbitrary HTML/script—use HTMLPurifier or similar in production).discover => false and explicitly define providers if fetching from known domains (e.g., YouTube, Twitter) to avoid DNS lookups and improve performance.$response->status (e.g., 200, 404) before rendering; fallback gracefully for invalid URLs.\Embera\Http\Provider to add custom oEmbed endpoints or override response parsing for services not natively supported.How can I help you explore Laravel packages today?