How to skip first row when importing file

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Skipping the First Row When Importing Files with Laravel and Maatwebsite-Excel Introduction In your project, you might want to import data from an Excel file (.xlsx or .csv) into a database using Laravel. The first row in many spreadsheets usually contains column headers that are not required for inserting the actual data. To avoid importing these header values, you need to bypass the first row during the import process. This blog post will explain how you can achieve this with Laravel and Maatwebsite-excel package. Skipping the First Row in Laravel 5.7 using the Excel Library The Maatwebsite-Excel library allows you to easily parse and import data from various file formats, including .xlsx and .csv files. The latest version of this library (3.1.0) has introduced some changes that might require adapting your code accordingly if it uses the deprecated functions or syntax. Example Code with Version 2 Syntax:
public function voter_import(Request $request)
{
    if (empty($request->file('file')->getRealPath())) 
    {
        return back()->with('success','No file selected');
    }
    else 
    {
        Excel::import(new VotersImport, $request->file('file'))->skip(1);
        return response('Import Successful, Please Refresh Page');
    }
}

class VotersImport implements ToModel
{
public function model(array $row)
   {
    return new Voter([
      'fname'          =>  $row[0],
      'lname'          =>  $row[1],
      'phone'          =>  $row[2],
      'gender'         =>  $row[3],
      'state'          =>  $row[4],
      'occupation'     =>  $row[5],
      'address'        =>  $row[6],
      'vin'            =>  $row[7],
      'dob'            =>  $row[8],
      'campaign_id'    =>  $row[9],
    ]);
   }
}
Problem with This Code The problem in the previous example is that it uses the deprecated version 2 syntax, which has been replaced by newer functions. The `skip()` method has been removed and replaced with a new object called `Reader`. Correct Example Code with Version 3 Syntax:
public function voter_import(Request $request)
{
    if (empty($request->file('file')->getRealPath())) 
    {
        return back()->with('success','No file selected');
    }
    else 
    {
        Excel::load($request->file('file'), function(Reader $reader) use ($table, $model) {
            foreach ($reader as $row)
                Voter::create($row->toArray());
        });
        return response('Import Successful, Please Refresh Page');
    }
}

class VotersImport implements ToModel
{
public function model(array $row)
   {
    return new Voter([
      'fname'          =>  $row['first_name'],
      'lname'          =>  $row['last_name'],
      'phone'          =>  $row['phone'],
      'gender'         =>  $row['gender'],
      'state'          =>  $row['state'],
      'occupation'     =>  $row['occupation'],
      'address'        =>  $row['address'],
      'vin'            =>  $row['vin'],
      'dob'            =>  $row['dob'],
      'campaign_id'    =>  $row['campaign_id'],
    ]);
   }
}
Conclusion In this blog post, we have discussed how to skip the first row of a file being imported using Laravel and Maatwebsite-excel library. We have provided an example code that demonstrates the correct syntax for version 3 of the library, ensuring your data import process is efficient and accurate. Remember to always check for the latest updates in the Maatwebsite-excel package and use it accordingly for optimal results.