title: Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?
body: <p>I made import data using Excel on Laravel Maatwebsite Excel 3.1. but when in the database there is the same data (Primary Key) then there is an error message </p>
  
  <blockquote>
    <p>integrity constraint violation: 1062 Duplicate entry '188281' for key
    'PRIMARY'</p>
  </blockquote>
  
  <p>I have tried to understand the documentation of the Maatwebsite but it still fails</p>
  
  <pre><code>public function storeData(Request $request)
          {
              //VALIDASI
              $this-&gt;validate($request, [
                  'file' =&gt; 'required|mimes:xls,xlsx'
              ]);
          if ($request-&gt;hasFile('file')) {
              $file = $request-&gt;file('file');
  
              // dd($file); //GET FILE;
              Excel::import(new MahasiswaImport, $file); //IMPORT FILE
              return redirect('/mahasiswa')-&gt;with(['status' =&gt; 'Upload success']);
          }
          return redirect('/mahasiswa')-&gt;with(['error' =&gt; 'Please choose file before']);
      }
  
  
  
  &lt;?php
  
  namespace App\Imports;
  
  use App\Mahasiswa;
  use Maatwebsite\Excel\Concerns\ToModel;
  use Maatwebsite\Excel\Concerns\WithHeadingRow;
  use Illuminate\Contracts\Queue\ShouldQueue;
  use Maatwebsite\Excel\Concerns\WithChunkReading;
  use Maatwebsite\Excel\Concerns\Importable;
  
  class MahasiswaImport implements ToModel, WithHeadingRow, WithChunkReading, ShouldQueue
  
  {
  
    use Importable;
  /**
  * @param array $row
  *
  * @return \Illuminate\Database\Eloquent\Model|null
  */
  public function model(array $row)
  {
      return new Mahasiswa([
        'nim' =&gt; $row['nim'],
        'slug' =&gt; str_slug($row['nim']),
        'nama_mahasiswa' =&gt; $row['nama_mahasiswa'],
        'email' =&gt; $row['email'],
        'kode_kelas' =&gt; $row['kode_kelas'],
        'alamat' =&gt; $row['alamat'],
        'kode_jurusan' =&gt; $row['kode_jurusan'],
        'kode_tahun_akademik' =&gt; $row['kode_tahun_akademik'],
        'no_hp' =&gt; $row['no_hp'],
        'tempat_lahir' =&gt; $row['tempat_lahir'],
        // 'tanggal_lahir' =&gt; $row['tanggal_lahir'],
        'password' =&gt; $row['password']
  
  
      ]);
  }
  
  
  public function chunkSize(): int
  {
      return 1000;
  }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/bugkx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bugkx.png" alt="dd($row) in model"></a></p>