Skip to content
This repository was archived by the owner on Jul 15, 2020. It is now read-only.

Commit 64de604

Browse files
Remove the need for mixins 🔥
1 parent d179d18 commit 64de604

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

resources/views/components/button.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ function openWidget() {
1212
if (!error && result && result.event === "success") {
1313
console.log('Done uploading..: ', result.info);
1414
document.getElementById("showImg").src = result.info.url;
15+
document.getElementById("showImg").width = 350;
16+
document.getElementById("showImg").height = 350;
1517
}
1618
}).open();
1719
}
1820
</script>
1921

2022
<div>
21-
<img src="" id="showImg" width="350" height="350" />
23+
<img src="" id="showImg" />
2224
</div>
2325

2426
<button type="button" onclick="openWidget()">

src/CloudinaryEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function unsignedUploadAsync($file, $uploadPreset, $options = [])
162162
/**
163163
* Uploads an asset to a Cloudinary account, not limited to images, but any type of file.
164164
*/
165-
public function uploadFiles($file, $options = [])
165+
public function uploadFile($file, $options = [])
166166
{
167167
$uploadOptions = array_merge($options, ['resource_type' => 'auto']);
168168

src/CloudinaryServiceProvider.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Unicodeveloper\Cloudinary;
44

5+
use Illuminate\Support\Facades\Request;
6+
use Illuminate\Http\UploadedFile;
57
use Illuminate\Support\Facades\Blade;
68
use Illuminate\Support\ServiceProvider;
79
use Unicodeveloper\Cloudinary\Commands\BackupFilesCommand;
@@ -21,6 +23,7 @@ class CloudinaryServiceProvider extends ServiceProvider
2123
*/
2224
public function boot()
2325
{
26+
$this->bootMacros();
2427
$this->bootResources();
2528
$this->bootDirectives();
2629
$this->bootComponents();
@@ -107,4 +110,18 @@ protected function bootComponents()
107110
{
108111
Blade::component('cloudinary::components.button', 'upload-button');
109112
}
113+
114+
/**
115+
* Boot the package macros that extends Laravel Uploaded File API.
116+
*
117+
* @return void
118+
*/
119+
protected function bootMacros()
120+
{
121+
$engine = new CloudinaryEngine;
122+
123+
UploadedFile::macro('storeOnCloudinary', function ($folder = null) use ($engine) {
124+
return $engine->uploadFile($this->getRealPath())->getSecurePath();
125+
});
126+
}
110127
}

src/Commands/BackupFilesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function handle(CloudinaryEngine $engine)
6262
try {
6363

6464
foreach($files as $file) {
65-
$engine->uploadFiles($file->getRealPath(), $folder ? ['folder' => $folder] : []);
65+
$engine->uploadFile($file->getRealPath(), $folder ? ['folder' => $folder] : []);
6666
$this->info('Uploading in progress...');
6767
}
6868

src/Commands/UploadFileCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function handle(CloudinaryEngine $engine)
5656

5757
try {
5858

59-
$engine->uploadFiles($remoteUrl);
59+
$engine->uploadFile($remoteUrl);
6060
$this->info('Uploading in progress...');
6161

6262
$this->info('Upload to Cloudinary completed!');

0 commit comments

Comments
 (0)