Skip to content

Laravel Cloudinary v2 Release Update

v2 of the Laravel Cloudinary package was recently tagged and released.

Laravel Cloudinary package install

The Laravel Cloudinary package is an SDK that empowers Laravel developers with the ability to fluently upload, optimize, store, transform and deliver media files with Cloudinary. It also provides an API to easily attach your media files to Laravel Eloquent models.

Here’s a highlight of the changes that shipped with Laravel Cloudinary v2:

  1. Full support for Laravel 9.
  2. A rewrite of the Cloudinary Adapter to work with Flysystem v3.
  3. Removal of deprecated methods to be compliant with Flystem v3.

Using the x-cld-upload-button Blade upload button component:

<!DOCTYPE html>
<html>
    <head>
        ...
        @cloudinaryJS
    </head>
    <body>
        <x-cld-upload-button>
            Upload Files
        </x-cld-upload-button>
    </body>
</html>
Code language: HTML, XML (xml)

Using the Cloudinary Facade

// Upload an Image File to Cloudinary with One line of Code
$uploadedFileUrl = Cloudinary::upload($request->file('file')->getRealPath())->getSecurePath();

// Upload a Video File to Cloudinary with One line of Code
$uploadedFileUrl = Cloudinary::uploadVideo($request->file('file')->getRealPath())->getSecurePath();

// Upload any File to Cloudinary with One line of Code
$uploadedFileUrl = Cloudinary::uploadFile($request->file('file')->getRealPath())->getSecurePath();
Code language: PHP (php)

Using the cloudinary() helper function:

// Upload an image file to cloudinary with one line of code
$uploadedFileUrl = cloudinary()->upload($request->file('file')->getRealPath())->getSecurePath();

// Upload a video file to cloudinary with one line of code
$uploadedFileUrl = cloudinary()->uploadVideo($request->file('file')->getRealPath())->getSecurePath();

// Upload any file  to cloudinary with one line of code
$uploadedFileUrl = cloudinary()->uploadFile($request->file('file')->getRealPath())->getSecurePath();

// Upload an existing remote file to Cloudinary with one line of code
$uploadedFileUrl = cloudinary()->uploadFile($remoteFileUrl)->getSecurePath();
Code language: PHP (php)

Using the $request object directly like so:

// Store the uploaded file on Cloudinary
$result = $request->file('file')->storeOnCloudinary();

// Store the uploaded file on Cloudinary
$result = $request->file->storeOnCloudinary();

// Store the uploaded file in the "lambogini" directory on Cloudinary
$result = $request->file->storeOnCloudinary('lambogini');

// Store the uploaded file in the "lambogini" directory on Cloudinary with the filename "prosper"
$result = $request->file->storeOnCloudinaryAs('lambogini', 'prosper');
Code language: PHP (php)

Displaying a file using the public id (otherwise known as stored name).

For instance, if a file was uploaded and stored as themagician, then the public id is themagician.

$url = cloudinary()->getUrl($publicId);

// get url from a file
$url = Cloudinary::getUrl($publicId);

// Blade Image Component for displaying images
<x-cld-image public-id="prosper" width="300" height="300"></x-cld-image> 

// Blade Video Component for displaying videos
<x-cld-video public-id="awesome"></x-cld-video> 
Code language: PHP (php)

Please head over to the package’s documentation to read more about how it attaches uploaded files to Laravel Eloquent models.

If you’re building apps with Laravel, this package can handle everything media related in your project!

Back to top

Featured Post