如何使用Laravel Excel在Laravel中导入多个Excel文件?
我正在尝试使用Laravel Excel在Laravel中导入多个文件。
我在刀片文件中有以下代码,该代码允许我选择多个文件:
<form action="{{ route('file-import') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group mb-4" style="max-width: 500px; margin: 0 auto;">
<div class="custom-file text-left">
<input type="file" name="file" class="custom-file-input" id="customFile" multiple>
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</div>
<button class="btn btn-primary">Import data</button>
</form>
在控制器中,我使用以下代码:
public function fileImport(Request $request)
{
Excel::import(new LogsImport, $request->file('file')->store('temp'));
return back();
}
它可以正常工作,但它仅导入我选择的第一个文件。 我相信我需要某种言论。我尝试了以下选项:
public function fileImport(Request $request)
{
foreach($request->file('file') as $f){
Excel::import(new LogsImport, $f->store('temp'));
}
return back();
}
但是使用此文件没有导入。
我还尝试打印$请求,但我得到了一个巨大的数组,但找不到任何相关的指向我上传的文件。
任何帮助将不胜感激。谢谢
I am trying to import multiple files in Laravel using Laravel Excel.
I have the following code in my blade file, which allows me to select multiple files to be uploaded:
<form action="{{ route('file-import') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group mb-4" style="max-width: 500px; margin: 0 auto;">
<div class="custom-file text-left">
<input type="file" name="file" class="custom-file-input" id="customFile" multiple>
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</div>
<button class="btn btn-primary">Import data</button>
</form>
In the controller I use the following code:
public function fileImport(Request $request)
{
Excel::import(new LogsImport, $request->file('file')->store('temp'));
return back();
}
It works fine but it only imports the first file I select.
I believe I need some kind of foreach statement. I tried the following option:
public function fileImport(Request $request)
{
foreach($request->file('file') as $f){
Excel::import(new LogsImport, $f->store('temp'));
}
return back();
}
But using this no file is getting imported.
I also tried printing $request but I get a huge array and I can't find anything relevant that points to the files I uploaded.
Any help would be appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用数组名称=“ file []”而不是名称=“文件”
try to use array name="file[]" instead of name="file"