PHP code example of previewlinks / laravel-previewlinks

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

    

previewlinks / laravel-previewlinks example snippets


return [

    /**
     * PreviewLinks API token
     *
     * Obtain one from https://previewlinks.io/app/account
     */
    'api_token' => env('PREVIEWLINKS_API_TOKEN'),

];

use PreviewLinks\PreviewLinks;

/** @var PreviewLinks $previewlinks */
$previewlinks = app(PreviewLinks::class);

$sites = $previewlinks->listSites();

$site = $previewlinks->showSite(siteId: 1);

$siteTemplates = $previewlinks->listSiteTemplates(siteId: 1);

// This will return a JSON response with the image URL, the request may take 4 to 8 seconds to complete
$downloadableImageUrl = $previewlinks->downloadImage(siteId: 1, templateId: 1, fields: [
    'previewlinks:title' => 'Hello from Laravel',
    'previewlinks:cta' => 'This is an example',
]);

// This method makes no API requests, we advise to use this over `downloadImage`
$signedImageUrl = $previewlinks->signedImageUrl(templateId: 1, [
    'previewlinks:title' => 'Hello from Laravel',
    'previewlinks:cta' => 'This is an example',
]);