PHP code example of cloudinary-labs / cloudinary-laravel

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

    

cloudinary-labs / cloudinary-laravel example snippets


// Upload
$uploadedFileUrl = cloudinary()->upload($request->file('file')->getRealPath())->getSecurePath();

// Upload with transformation
$uploadedFileUrl = cloudinary()->upload($request->file('file')->getRealPath(), [
    'folder' => 'uploads',
    'transformation' => [
        'width' => 400,
        'height' => 400,
        'crop' => 'fill'
    ]
])->getSecurePath();

// Get URL
$url = cloudinary()->getUrl($publicId);

// Check if file exists
$exists = Storage::disk('cloudinary')->fileExists($publicId);

use CloudinaryLabs\CloudinaryLaravel\MediaAlly;

class Page extends Model
{
    use MediaAlly;
    // ...
}

// Attach media
$page->attachMedia($request->file('file'));

// Retrieve media
$allMedia = $page->fetchAllMedia();
$firstMedia = $page->fetchFirstMedia();
$lastMedia = $page->fetchLastMedia();

// Update media
$page->updateMedia($newFile);

// Detach media
$page->detachMedia($file);

use CloudinaryLabs\CloudinaryLaravel\Facades\Cloudinary;

$url = Cloudinary::getUrl($publicId);
// or
$url = cloudinary()->getUrl($publicId);
bash
php artisan vendor:publish --provider="CloudinaryLabs\CloudinaryLaravel\CloudinaryServiceProvider" --tag="cloudinary-laravel-config"
bash
php artisan cloudinary:backup
php artisan cloudinary:delete
php artisan cloudinary:fetch
php artisan cloudinary:rename
php artisan cloudinary:upload