0

When I import the excel file to the database, the file imported to the database but it inserts together with the excel first row which is the column name, I don't know how to make it upload only the data start from the second row.

Below is the code that I use in the controller to import

public function import()
{
    Excel::import(new StudentImport,request()->file('file'));

    return redirect('/admin/dashboard')->with('flash_message_success','Upload successful');
}

I expected the data inserted to the database starting from the second row and skip the first row which is the column name.

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
Gucci Gang
  • 19
  • 1
  • 3

1 Answers1

0

You need to specify the headingRow

 public function headingRow(): int
 {
    return 1;
 }

and your import class will be

class StudentImport implements ToModel, WithHeadingRow{}

Refer docs

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105