PHP code example of teners / laravel-link-preview

1. Go to this page and download the library: Download teners/laravel-link-preview 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/ */

    

teners / laravel-link-preview example snippets


use Teners\LaravelLinkPreview\LinkPreview;

// Get link preview for any URL
$preview = LinkPreview::getPreview('https://example.com');

// Returns an array with extracted metadata
/*
[
    'title' => 'Example Website',
    'description' => 'This is an example website description',
    'cover' => 'https://example.com/image.jpg',
    'author' => 'John Doe',
    'keywords' => 'example, website, demo',
    'icon' => 'https://example.com/favicon.ico',
    'video' => 'https://example.com/video.mp4',
    'video_type' => 'video/mp4'
]
*/

// Enable/disable caching
'enable_caching' => env('LINK_PREVIEW_ENABLE_CACHING', true),

// Cache duration in seconds (default: 1 week)
'cache_duration' => env('LINK_PREVIEW_CACHE_DURATION', 604800),

// Cache type: 'model' (database) or 'app' (Laravel cache)
'cache_type' => env('LINK_PREVIEW_CACHE_TYPE', 'model'),

// Request timeout
'timeout' => env('LINK_PREVIEW_TIMEOUT', 15),

// Connection timeout
'connect_timeout' => env('LINK_PREVIEW_CONNECT_TIMEOUT', 10),

// Maximum redirects
'max_redirects' => env('LINK_PREVIEW_MAX_REDIRECTS', 5),

// User agent
'user_agent' => env('LINK_PREVIEW_USER_AGENT', 'Teners/LinkPreview v2.0.0 (Compatible Bot)'),

// SSL verification
'verify_ssl' => env('LINK_PREVIEW_VERIFY_SSL', true),
bash
php artisan vendor:publish --provider="Teners\LaravelLinkPreview\LaravelLinkPreviewServiceProvider" --tag="link-preview-config"
bash
php artisan migrate