问题描述
当尝试在 Laravel 5.8.38 中实现多个上传文件功能时,出现数组到字符串转换错误 找不到任何决定
刀片式的我很简单:
Generator
在存储功能中,我有:
该函数创建一个遗产(一个财产)。如果用户为其添加了一些图片,我们会将这些图片添加到本地路径中并将其添加到数据库中
如果我评论<form class="form-horizontal" action="{{route('admin.estates.store')}}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<label for="estate_image" class="mt-4">Images</label>
<input type="file" name="estate_image[]" multiple>
<input class="btn btn-primary" type="submit" value="Сохранить">
<input type="hidden" name="created_by" value="{{Auth::id()}}">
</form>
,效果很好
但在这种情况下,遗产不会添加到数据库中
$estate = Estate::create($request->all());
我从输入中获得的数组
public function store(Request $request)
{
$estate = Estate::create($request->all());
if($request->hasFile('estate_image')) {
foreach ($request->file('estate_image') as $image) {
// do some image resize and store it on local path
$filename = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('images\\' . $filename);
Image::make($image)->resize(800,400)->save($location);
// add image info in database
$estateimage = new EstateImages();
$estateimage->image_path = $location;
$estateimage->image_alt = 'testalt';
$estateimage->save();
}
}
}
据了解,foreach不会启动,但不理解为什么(试图删除foreach中的所有代码,并在其中留下简单的回声'Hello!';;,具有相同的错误。 在StackOverflow中也看到了同样的问题,但是任何问题都帮助了我...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)