我尝试使用存储上传多个文件,所以这是我的代码:
public function store(Request $request)
{
$gallery = new Gallery();
$gallery->name = $request->name;
$gallery->description = $request->description;
$gallery->save();
$path = 'public'.'/'.str_slug($request->name);
Storage::makeDirectory(str_slug($request->name));
$image = new Image();
if ( is_array($request->images)) {
foreach ($request->images as $file) {
$image->gallery_id = $gallery->id;
$image->name = $file->getClientOriginalName();
$image->extension = $file->extension();
$image->save();
Storage::putFileAs($path, $file);
}
} else {
$image->gallery_id = $gallery->id;
$image->name = $request->images->getClientOriginalName();
$image->save();
}
}
我已经像这样设置了我的表单:
<div class="form-group">
<label for="images" class="col-md-2 control-label">Images</label>
<div class="col-md-6">
<input type="file" class="form-control" name="images[]" id="images[]" multiple>
</div>
</div>
它给了我这样的错误:
“类型错误:函数 Illuminate\Filesystem\FilesystemAdapter::putFileAs() 的参数太少,在第 343 行的 E:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemManager.php 中传递了 2 个至少 3 个预计 ◀"
所以问题是我使用 is_array 检查它是否有多个文件的方式是否正确?第二个什么会导致这个问题?