Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,26 @@ Other Blade components you can use are:
<x-cld-video public-id="awesome"></x-cld-video> // Blade Video Component for displaying videos
```

To get the upload image link from the widget in your controller, simply set a route and controller action in your `.env`. For example:

```php
CLOUDINARY_UPLOAD_ROUTE=api/cloudinary-js-upload
CLOUDINARY_UPLOAD_ACTION=App\Http\Controllers\Api\CloudinaryController@upload
```

Make sure to specify the full path to the controller. You should be able to get the URL like so:

```php
...
class CloudinaryController extends Controller
{
public function upload(Request $request)
{
$url = $request->get('cloud_image_url');
}
}
```

## **Media Management via The Command Line**:

```bash
Expand Down Expand Up @@ -450,7 +470,17 @@ return [
* Upload Preset From Cloudinary Dashboard
*
*/
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET')
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET'),

/**
* Route to get cloud_image_url from Blade Upload Widget
*/
'upload_route' => env('CLOUDINARY_UPLOAD_ROUTE'),

/**
* Controller action to get cloud_image_url from Blade Upload Widget
*/
'upload_action' => env('CLOUDINARY_UPLOAD_ACTION'),
];
```

Expand Down
12 changes: 11 additions & 1 deletion config/cloudinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,15 @@
* Upload Preset From Cloudinary Dashboard
*
*/
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET')
'upload_preset' => env('CLOUDINARY_UPLOAD_PRESET'),

/**
* Route to get cloud_image_url from Blade Upload Widget
*/
'upload_route' => env('CLOUDINARY_UPLOAD_ROUTE'),

/**
* Controller action to get cloud_image_url from Blade Upload Widget
*/
'upload_action' => env('CLOUDINARY_UPLOAD_ACTION'),
];
26 changes: 24 additions & 2 deletions resources/views/components/button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var cloudName = @json(Str::after(config('cloudinary.cloud_url'),'@'));
var uploadPreset = @json(config('cloudinary.upload_preset'));
var uploadRoute = @json(config('cloudinary.upload_route'));

function openWidget() {
window.cloudinary.openUploadWidget(
Expand All @@ -10,8 +11,29 @@ function openWidget() {
},
(error, result) => {
if (!error && result && result.event === "success") {
console.log('Done uploading..');
localStorage.setItem("cloud_image_url", result.info.url);
console.log('Done uploading..');
localStorage.setItem("cloud_image_url", result.info.url);
try {
if (uploadRoute) {
fetch(uploadRoute, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
body: JSON.stringify({cloud_image_url: result.info.url})
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
}
} catch (e) {
console.error(e);
}
}
}).open();
}
Expand Down
14 changes: 14 additions & 0 deletions src/CloudinaryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function boot()
$this->bootCommands();
$this->bootPublishing();
$this->bootCloudinaryDriver();
$this->bootRoutes();
}

/**
Expand Down Expand Up @@ -166,6 +168,18 @@ function ($app, $config) {
);
}

/**
* Boot the package routes.
*
* @return void
*/
protected function bootRoutes()
{
if (config('cloudinary.upload_route')) {
Route::post(config('cloudinary.upload_route'), config('cloudinary.upload_action'));
}
}

/**
* Register any package services.
*
Expand Down