我通过DropzoneJS保存了文件(图片),我可以将它们放到我喜欢的任何地方,但我的问题是如何编辑它们。我转到我的产品编辑页面我可以看到我的图像,但不知道如何编辑它们(删除其中一些或添加到它们)
这是我的代码来获取它们:
public function edit($id)
{
$product = Product::findOrFail($id);
$images = DB::table('images')->where('imageable_id', '=', $product->id)->get();
// rest of codes
}
我在编辑页面中显示我的图像,如:
@foreach($images as $test)
<img src="{{url('/')}}/images/{{$test->name}}" alt="test" width="100" height="100">
@endforeach
screenshot
@linktoahref方式对我有效,他建议在编辑页面上not bad idea totally
制作新的上传器以将图像添加到我的产品中,但这不是我和# 39;我正在寻找。
我尝试实现的是使用DropZone本身来返回我的存在 每种产品的图像,并能够删除或添加。
我读了许多问题,文章等等。我得到的是我必须使用mockFile
我不知道它。如果有人能帮助我完成这项工作,我将不胜感激。
感谢。
答案 0 :(得分:1)
对于DELETE,您可以在图像旁边添加一个按钮,该按钮将触发相应控制器的destroy
方法
@foreach($images as $test)
<img src="{{ url('/') }}/images/{{ $test->name }}" alt="test" width="100" height="100">
<a href="#" class="btn btn-danger"
onclick="event.preventDefault();
document.getElementById('image-{{ $test->id }}').submit();">
DELETE
</a>
<form id="image-{{ $test->id }}"
action="{{ route('images.destroy', ['id' => $test->id]) }}"
method="POST" style="display: none;">
{{ csrf_field() }}
{{ method_field('DELETE') }}
</form>
@endforeach
并在ImageController的destroy
方法(或您的自定义控制器的方法,确保方法类型相同)中处理图像的删除。
public function destroy(Image $image)
{
// Destroy the Image
Storage::delete($image->name);
// Redirect Back
return redirect()->back();
}