title: Ignore inserting duplicated data into the DB does not seem to be working properly
body: <p>I'm working with Laravel 5.8 and LaravelExcel for importing an Excel file that holds a column named &quot;National Code&quot; and this code must be unique in the Database.</p>
  <p>So if a user entered repeated National Codes in his Excel file, a message has to appear and show repeated National Codes to him.</p>
  <p>So I coded this at the Import Class:</p>
  <pre><code>    $query=DB::table('olympiad_1400');
      
      $repeated = [];
      
      foreach($formatArray as $arr){
          if(!$query-&gt;where('mys_ncode',$arr['nationalCode'])-&gt;exists()){
             $query-&gt;insert([
                  'mys_object_id' =&gt; $objectId,
                  'mys_object_type_id' =&gt; $objectTypeId,
                  'mys_olp_id' =&gt; 4,
                  'mys_name' =&gt; $arr['name'],
                  'mys_fname' =&gt; $arr['family'],
                  'mys_ncode' =&gt; $arr['nationalCode'],
                  'mys_paid_price' =&gt; $arr['price'],
                  'mys_creator_id' =&gt; auth()-&gt;user()-&gt;usr_id,
             ]);
          }else{
             array_push($repeated, $arr['nationalCode']);
          }
      }
      
      if(!empty($repeated)){
          Session::flash('repeated',$repeated);
      }
  </code></pre>
  <p>Now if I test this via uploading an Excel file that contains repeated National Codes which already exists in the DB, it shows the first element in the session <code>$repeated</code> (and ignores inserting it) but surprisingly inserts all the others (however, the are all duplicated).</p>
  <p>So how can I fix this and ignore inserting repeated National Codes into the Database?</p>