我有foreach循环的产品产品在篮子里可以得到许多照片从用户用户上传照片到产品(出售农场的照片)模态是在foreach循环
当模态是打开dropzone不工作,并得到这个错误:
服务器错误:1放置区已连接。
我的模态
<div class="modal fade" id="productmultiplephoto-{{$product->pivot->id}}" role="dialog" aria-labelledby="productmultiplephoto" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header pb-0">
<h5 class="modal-title" id="price-changes-modal-label"></h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="__img">
<div class="form-group">
<input type="hidden" name="original_name[]" id="product-photo">
<input name="product_id" value="{{$product->id}}" type="hidden" id="product_id" >
<input name="product_pivot" value="{{$product->pivot->id}}" type="hidden" id="product_pivot" >
<input name="cartproduct_id" type="hidden" id="cartproduct_id"value="{{$product->pivot->id}}" >
<label for="photog">upload</label>
<input type="hidden" name="original_name[]" id="product-photo">
<div id="photog" class="dropzone" ></div>
</div>
</div>
</div>
</div>
</div>
我的剧本
<script>
Dropzone.autoDiscover = false;
var photosGallery = []
var drop = new Dropzone('#photog', {
addRemoveLinks: true,
url: "{{ route('front.photouser.upload') }}",
type:"POST",
sending: function(file, xhr, formData){
formData.append("_token","{{csrf_token()}}")
formData.append("product_id", document.getElementById('product_id').value);
formData.append("product_pivot", document.getElementById('product_pivot').value);
formData.append("cartproduct_id", document.getElementById('cartproduct_id').value);
},
success: function(file, response){
photosGallery.push(response.original_name)
if (response['level'] == 1) {
$('.level1_message').html(response['message']);
}
}
});
productGallery = function(){
document.getElementById('product-photo').value = photosGallery
}
</script>
我的按钮模态
@foreach($cart->products as $product)
<button type="button" data-toggle="modal" data-target="#productmultiplephoto-{{$product->pivot->id}}" class="btn-primary-multiple btn-primary-cm btn-with-icon">
<i class="mdi mdi-plus-box-multiple"></i>
upload
</button>
@endforeach
包含模态部分
@include('front::products.partials.add-multiple-photo')
1条答案
按热度按时间0g0grzrc1#
像这样更新你的div:
对于循环的每次迭代,您还应该为每个产品生成一个具有唯一name属性的新隐藏input元素,以便在上载文件时,可以知道该文件要添加到哪个产品
完整JS:
像这样更新你的模态div: