PHP code example of vhar / embed-video

1. Go to this page and download the library: Download vhar/embed-video library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vhar / embed-video example snippets


try {
    return EmbedVideo::handle('https://www.youtube.com/watch?v=gpn_4tWz1w8');
} catch (\Exception $exception) {
    return ['error' => $exception->getMessage()];
}

{
  id: "gpn_4tWz1w8"
  video: "https://www.youtube.com/embed/gpn_4tWz1w8"
  cover: "https://img.youtube.com/vi/gpn_4tWz1w8/0.jpg"
}

try {
    return EmbedVideo::hosting('youtube')->handle('https://www.youtube.com/watch?v=gpn_4tWz1w8');
} catch (\Exception $exception) {
    return ['error' => $exception->getMessage()];
}

use Vhar\EmbedVideo\Rules\EmbedVideoRule;

$request->validate([
    'name' => ['

public function handle(string $url): EmbedDataDTO
{
    ...    
    return new EmbedDataDTO(
        id: $id, 
        video: $embedURL, 
        cover: $coverURL
    );
}

public function allowedDomains(): array
{
    return [
        'youtu.be',
        'youtube.com',
    ];
}

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        ...
        \Vhar\EmbedVideo\Facades\VideoHosting::hosting('you_alias', \YouNamespace\YouClassHandlerService::class);
    }
}