PHP code example of vhar / laravel-embed-video

1. Go to this page and download the library: Download vhar/laravel-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 / laravel-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()];
}

public function handle(string $url): EmbedData
{
    ...    
    $data = new EmbedData();

    return $data->setId($id)->setVideo($embedURL)->setCover($coverURL);}

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

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        ...
        \Vhar\LaravelEmbedVideo\Facades\VideoHosting::hosting('you_alias', \YouNamespace\YouClassHandlerService::class);
    }
}
xml
<testsuites>instance
    ...
    <testsuite name="Embed Video">
        <directory suffix="Test.php">./vendor/vhar/laravel-embed-video/tests/</directory>
    </testsuite>
</testsuites>