Laravel Cloudinary v2 Release Update
Tags: programming, media, cloudinary, laravel
Published: 2022-06-28 14:50:29

I recently tagged and released v2 of the [Laravel Cloudinary package](https://github.com/cloudinary-labs/cloudinary-laravel).


![Laravel Cloudinary package install](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2ifo6ojfs165mwtgk5r.png) 

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.

I'll briefly highlight the changes that shipped with **Laravel Cloudinary v2** below:

1. It fully supports Laravel 9.
2. Rewrote the [Cloudinary Adapter](https://github.com/cloudinary-labs/cloudinary-laravel/blob/master/src/CloudinaryAdapter.php) to work with [Flysystem v3](https://github.com/thephpleague/flysystem).
3. Remove deprecated methods to be compliant with [Flystem v3](https://github.com/thephpleague/flysystem).

**A Recap of Laravel Cloudinary features:**

### 1. File Uploads via a frontend Upload Widget

Use the `x-cld-upload-button` Blade upload button component like so:

```html
<!DOCTYPE html>
<html>
    <head>
        ...
        @cloudinaryJS
    </head>
    <body>
        <x-cld-upload-button>
            Upload Files
        </x-cld-upload-button>
    </body>
</html>
```


### 2. File Uploads via the Controller or a Service Class


**_Using the Cloudinary Facade_**

```php
// 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();
```

**_Using the cloudinary() helper function_**

```php
// 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();
```

**_Use the $request object directly like so:_**

```php
// 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');
```

### 3. Display Uploaded Files

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**.

```php
$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> 
```

### 4. Attach Files to Eloquent Models

Please head over to the [package's documentation](https://github.com/cloudinary-labs/cloudinary-laravel#attach-files-to-laravel-eloquent-models) to read more about how it attaches uploaded files to Laravel Eloquent models.


## Conclusion

If you're building apps with Laravel, you should explore using this package to handle everything media related in your project.

Feel free to drop your questions, concerns and thoughts in the comment section.