Skip to content

Commit b2a8b2f

Browse files
committed
Handle ‘multiple_images’ field - WIP: !delete yet
1 parent e1c4bc1 commit b2a8b2f

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

resources/views/vendor/voyager/page-blocks/edit-add.blade.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@
127127
@php
128128
$template = $block->template();
129129
$dataTypeContent = $block->data;
130-
/* Hack: for latest Voyager "data-id" requirement on image field */
131-
$dataTypeContent->id = 0;
132130
@endphp
133131

134132
@if ($block->type === 'template')
@@ -168,6 +166,21 @@
168166
$(this).closest('.form-group').addClass('vpb-image-group');
169167
});
170168
169+
/**
170+
* MULTIPLE-IMAGES Delete function
171+
*/
172+
/*$(".remove-multi-image").on('click', function(e){
173+
e.preventDefault();
174+
var result = confirm("Are you sure you want to delete this image?");
175+
if (result) {
176+
$.post('{{-- route('voyager.page-blocks.delete-multiple-image') --}}', {
177+
field: $(this).data('id'),
178+
file_name: $(this).data('file-name'),
179+
_token: '{{ csrf_token() }}'
180+
});
181+
}
182+
});*/
183+
171184
/**
172185
* Confirm DELETE block
173186
*/

resources/views/vendor/voyager/page-blocks/partials/template.blade.php

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class="panel-action panel-collapse-icon voyager-angle-up"
3434
<div class="@if (strpos($row->partial, 'rich_text_box') !== false)col-md-12 @else col-md-6 @endif">
3535
<div class="form-group">
3636
<label>{{ $row->display_name }}</label>
37+
@php
38+
/* For 'multiple images' field - pass through the ID to identify the specific field */
39+
$dataTypeContent->id = $row->field;
40+
@endphp
3741
@include($row->partial)
3842
</div> <!-- /.form-group -->
3943
</div> <!-- /.col -->

src/Http/Controllers/PageBlockController.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public function update(Request $request, $id)
5959
foreach ($template->fields as $row) {
6060
$existingData = $block->data;
6161

62-
if ($row->partial === 'voyager::formfields.image') {
62+
if (
63+
$row->partial === 'voyager::formfields.image'
64+
|| $row->partial === 'voyager::formfields.multiple_images'
65+
) {
6366
if (is_null($request->file($row->field))) {
6467
if (isset($existingData->{$row->field})) {
6568
$data[$row->field] = $existingData->{$row->field};

src/Traits/Blocks.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,18 @@ protected function prepareTemplateBlockTypes($block)
8484

8585
public function uploadImages(Request $request, array $data): array
8686
{
87-
foreach ($request->files as $key => $file) {
88-
$filePath = $request->file($key)->store('public/blocks');
89-
$data[$key] = str_replace('public/', '', $filePath);
87+
foreach ($request->files as $key => $field) {
88+
if (is_array($request->file($key))) {
89+
$multiImages = array();
90+
foreach ($request->file($key) as $key2 => $file) {
91+
$filePath = $file->store('public/blocks');
92+
$multiImages[] = str_replace('public/', '', $filePath);
93+
}
94+
$data[$key] = json_encode($multiImages);
95+
} else {
96+
$filePath = $request->file($key)->store('public/blocks');
97+
$data[$key] = str_replace('public/', '', $filePath);
98+
}
9099
}
91100

92101
return $data;

0 commit comments

Comments
 (0)