当我尝试在控制器内部执行循环时,出现错误Invalid argument supplied for foreach(),但我真的不知道为什么。我有一个form应该可以上传多个文件的地方
这是我到目前为止所得到的:
use App\SingleApplication;
use App\SingleApplicationFile;
$application = SingleApplication::create([
'email' => request()->email,
'name' => request()->name,
...// more fields
]);
$allowedfileExtension = ['pdf', 'jpg', 'png', 'docx'];
$files = request()->has('attachment');
if ($files) {
foreach ($files as $file) {
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$filesize = $file->getSize();
$check = in_array($extension, $allowedfileExtension);
if ($check) {
foreach ($file as $att) {
$filename = Storage::disk('local')->put('attachments', request()->file($att));
SingleApplicationFile::create([
'files_id' => $application->id,
'single_application_id' => $application->id,
'attachment' => $filename,
'attachment_name' => $extension,
'attachment_size' => $filesize,
]);
}
}
}
}
那么,我在这里做错了什么?
潇潇雨雨