Skip to content

Commit 1f774af

Browse files
committed
add components
1 parent 65be7db commit 1f774af

File tree

4 files changed

+549
-0
lines changed

4 files changed

+549
-0
lines changed

src/CloudinaryServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function boot(): void
3838
return new FilesystemAdapter(new Filesystem($adapter, $config), $adapter, $config);
3939
});
4040

41+
$this->loadViewsFrom(__DIR__.'/../views', 'cloudinary');
42+
4143
$this->publishes([
4244
__DIR__.'/../config/cloudinary.php' => config_path('cloudinary.php'),
4345
], 'cloudinary-config');

views/components/button.blade.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script src="https://widget.cloudinary.com/v2.0/global/all.js" type="text/javascript"></script>
2+
<script type="text/javascript">
3+
var cloudName = @json(Str::after(config('cloudinary.cloud_url'), '@'));
4+
var uploadPreset = @json(config('cloudinary.upload_preset'));
5+
var uploadRoute = @json(config('cloudinary.upload_route'));
6+
7+
function openWidget() {
8+
window.cloudinary.openUploadWidget({
9+
cloud_name: cloudName,
10+
upload_preset: uploadPreset
11+
},
12+
(error, result) => {
13+
if (!error && result && result.event === "success") {
14+
console.log('Done uploading..');
15+
localStorage.setItem("cloud_image_url", result.info.url);
16+
try {
17+
if (uploadRoute) {
18+
fetch(uploadRoute, {
19+
method: 'POST',
20+
headers: {
21+
'Content-Type': 'application/json',
22+
'X-CSRF-TOKEN': '{{ csrf_token() }}'
23+
},
24+
body: JSON.stringify({
25+
cloud_image_url: result.info.url
26+
})
27+
})
28+
.then(response => response.json())
29+
.then(data => {
30+
console.log(data);
31+
})
32+
.catch(error => {
33+
console.error('Error:', error);
34+
});
35+
}
36+
} catch (e) {
37+
console.error(e);
38+
}
39+
}
40+
}).open();
41+
}
42+
</script>
43+
44+
<button
45+
type="button"
46+
onclick="openWidget()"
47+
{{ $attributes }}
48+
>
49+
{{ $slot }}
50+
</button>

0 commit comments

Comments
 (0)