【发布时间】:2017-12-08 02:40:16
【问题描述】:
我有一个模态,可以像这样将图像上传到图库:
<div id="imagesModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<form name="imagesForm" id="addImages" class="form-horizontal dropzone" role="form" method="POST" action="{{ route('images.add') }}" enctype="multipart/form-data">
{{ csrf_field() }}
{{ method_field('POST') }}
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
这是我的 jquery 脚本:
$( "#addImages" ).click(function(event) {
event.preventDefault();
save_method = 'add';
$('input[name=_method]').val('POST');
$('#imagesModal').modal("show");
$('#imagesForm')[0].reset();
$('.modal-title').text('Add Images')
});
Dropzone.options.addImages = {
paramName: "images", // The name that will be used to transfer the file
maxFilesize: 2, // MB
};
and i already add the route and the function
public function store(Request $request)
{
$gallery = Gallery::find($request->id);
$path = 'public'.'/'.str_slug($gallery->name);
foreach ($request->images as $file) {
$image = new Image();
$image->gallery_id = $gallery->id;
$image->name = $file->getClientOriginalName();
$image->extension = $file->extension();
$image->size = $file->getClientSize();
$image->save();
// Or any custom name as the third argument
Storage::putFileAs($path, $file, $file->getClientOriginalName());
}
}
我的问题是我不知道如何传递画廊 ID,以便将其访问到函数中?我有一些想法将其放在按钮中的 data-gallery-id 上,但是如何传递该数据以便将其与图像一起发送?
【问题讨论】:
标签: laravel laravel-5 dropzone.js