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