PHP code example of cardei / link-preview

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

    

cardei / link-preview example snippets


return [
    'enable_logging' => env('LINK_PREVIEW_ENABLE_LOGS', false),
];

$linkPreview = app('link-preview');
$preview = $linkPreview->setUrl('https://example.com')->getPreview();

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Cardei\LinkPreview\Facades\LinkPreview;

class PreviewController extends Controller
{
    public function showPreview(Request $request)
    {
        $url = $request->input('url');
        $preview = LinkPreview::setUrl($url)->getPreview();
        
        return view('preview', ['preview' => $preview]);
    }
}
bash
php artisan vendor:publish --tag=link-preview-config