laravel - 使用许多选择器 laravel 将照片上传到数据库
问题描述
我的表单中有 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 个选择图像的地址并保存它们?
解决方案
推荐阅读
- c++ - 为什么我在使用不同语言的相同代码上得到不同的答案?
- pytorch - 从检查点加载模型不起作用
- lua - LuaForWindows,更新 Lua
- javascript - chartjs update() 没有更新
- rest - REST:如何删除一个资源并选择删除另一个资源?
- php - axios,无法将数据从反应组件传递到 PHP 文件
- teradata - Terdata 使用井号作为字段名称
- reactjs - 表达式大小超过 Google AMP 状态中的最大值
- java - 使用轻量级流 API 流获取元素匹配的索引
- azure - 在 azure 自动化中运行 powershell 代码时失败