我的表单中有 1 个选择图像,它只选择一张照片,我的控制器只能在数据库中存储一个图像地址,但我想在我的前面有 4 个选择图像,它们的全名是这样的图像:
<div class="image-upload-wrap">
<input class="file-upload-input" type='file' accept="image/*" name="image"/>
<div class="drag-text">
<h5>Select</h5>
</div>
</div>
<div class="image-upload-wrap">
<input class="file-upload-input" type='file' accept="image/*" name="image"/>
<div class="drag-text">
<h5>Select</h5>
</div>
</div>
<div class="image-upload-wrap">
<input class="file-upload-input" type='file' accept="image/*" name="image"/>
<div class="drag-text">
<h5>Select</h5>
</div>
</div>
<div class="image-upload-wrap">
<input class="file-upload-input" type='file' accept="image/*" name="image"/>
<div class="drag-text">
<h5>Select</h5>
</div>
</div>
这是我的控制器:
public function store(Request $request,Poster $poster)
{
$ValidatedData = $request->validate([
'title' => 'required',
'image' => 'mimes:jpeg,png,jpg,JPG,bmp|max:2048',
'body' => 'nullable',
]);
if ($request->hasFile('image')){
$ValidatedData['image'] = $request->file('image')->store('/posters/images');
try {
Poster::create($ValidatedData);
} catch (Exception $exception) {
switch ($exception->getCode()) {
case 23000:
$msg = "the entered title is duplicate";
break;
}
return redirect(route('admin.posters.create'))->with('warning', $msg);
}
$msg = "post saving was successful";
return redirect(route('admin.posters'))->with('success', $msg);
}
如何更改我的控制器以便能够在数据库中存储所有 4 个选择图像的地址并保存它们?