1

I'm using SpartnerNL/Laravel-Excel and I'm trying to import multiple csv files to database.

Controller:

public function importStatement(Request $request) 
    {
        foreach ($request->file('file') as $file) {
        Excel::import(new StatementsImport, $file);
        }
               
        return back();
    }

I tried importing single csv file and it worked using:

public function importStatement(Request $request) 
    {
        Excel::import(new StatementsImport, $file);

        return back();
    }

My problem is when I'm importing multiple csv files.

Blade:

<form action="{{ route('admin.statements.importStatement') }}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
     <div class="p-6 text-center">
          <input id="file" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" multiple name="file">
          <button type="submit" >Import</button>
     </div>
</form>

1 Answer 1

1

I've solved my problem by following the answer here:

I edited my blade to:

<form action="{{ route('admin.statements.importStatement') }}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
     <div class="p-6 text-center">
          <input id="file" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" multiple name="file[]">
          <button type="submit" >Import</button>
     </div>
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.