laravel - 如何将图像的原始名称放入数组中?
问题描述
大家好,我尝试上传两张图片,但是当我dd
使用 $filename 时,我在数组中只有一个名称
$data = $this->validate([
'image.*' => 'image|max:1024', // 1MB Max
]);
if(!empty($this->image)){
$filename = [];
foreach ($this->image as $img) {
$filename = $img->storeAs('public/images', 'image_' . time() . $img->getClientOriginalName());
}
$data['image'] = $filename;
dd($filename);
}
因为当dd
我创建它的数据时,它只传递一个名称
if($this->galleryId){
Gallery::find($this->galleryId)->update($data);
$action = 'edit';
}else{
dd($data);
Gallery::create($data);
$action = 'store';
}
这是我的数据dd
"public/images/image_1628844415Facebook-0064.jpg"
解决方案
承格这条线
$filename = $img->storeAs('public/images', 'image_' . time() . $img->getClientOriginalName());
至
$filename[] = $img->storeAs('public/images', 'image_' . time() . $img->getClientOriginalName());
推荐阅读
- javascript - 在表格上显示数组时变得未定义
- flutter - 颤振下拉菜单选择不适用于有状态小部件
- python - 循环遍历CSV行并使用python从前一行中减去当前行
- c# - Process.Start("Excel.exe") 立即退出
- typescript - 省略具有泛型类型的类的属性
- powershell - Hyper-V:制作一个脚本,提取计算机名称的最后 6 位,将其转换为十六进制,然后插入为 VM 的 MAC 地址(最后 8 位)
- windows - Gitian windows 编译不工作(时间错误)
- python - PyTorch 和 TensorFlow 对象检测 - 评估 - 对象类型
不能安全地解释为整数 - javascript - 使用 next 方法创建一个迭代器,该方法在调用 .next 时返回数组的每个值
- java - ETL 设计:我应该使用什么队列而不是我的 SQL 表并且仍然能够并行处理?