title: Laravel: Do not import duplicate datas Excel
body: <p>I have an issue when importing datas from an Excel file. My import controller is working just fine but it adds duplicate datas and i need to import the same datas often.</p>
  
  <p>This is my attempt which doesn't work.</p>
  
  <p>My postImportAttendee controller (My project is using Attendize):</p>
  
  <pre><code>  public function postImportAttendee(Request $request, $event_id)
      {
          $rules = [
              'ticket_id'  =&gt; 'required|exists:tickets,id,account_id,' . \Auth::user()-&gt;account_id,
              'attendees_list' =&gt; 'required|mimes:csv,txt,xlsx|max:5000|',
          ];
  
          $messages = [
              'ticket_id.exists' =&gt; trans("Controllers.ticket_not_exists_error"),
          ];
  
          $validator = Validator::make($request-&gt;all(), $rules, $messages);
          if ($validator-&gt;fails()) {
              return response()-&gt;json([
                  'status'   =&gt; 'error',
                  'messages' =&gt; $validator-&gt;messages()-&gt;toArray(),
              ]);
  
          }
          $enveloppe = [];
          $ticket_id = $request-&gt;get('ticket_id');
          $event = Event::findOrFail($event_id);
          $ticket_price = 0;
          $email_attendee = $request-&gt;get('email_ticket');
          $num_added = 0;
          if ($request-&gt;file('attendees_list')) {
  
            $the_file = Excel::load($request-&gt;file('attendees_list')-&gt;getRealPath(), function ($reader) {
              })-&gt;get();
  
              if(!empty($the_file) &amp;&amp; $the_file-&gt;count()){
              // Loop through
              foreach ($the_file as $key =&gt; $value) {
  
  
                      if (array_key_exists($value-&gt;enveloppe, $enveloppe))
                          continue;
  
                      $rows[] = ['enveloppe' =&gt; $value-&gt;enveloppe, 'first_name' =&gt; $value-&gt;first_name, 'last_name' =&gt; $value-&gt;last_name, 'company' =&gt; $value-&gt;company, 'email' =&gt; $value-&gt;email, 'sender' =&gt; $value-&gt;sender];
  
  
                      $enveloppe[$value-&gt;enveloppe] = true; // or array_push
  
                    }
  
                    if (!empty($rows['enveloppe']) &amp;&amp; !empty($rows['last_name'])) {
  
                      $num_added++;
                      $attendee_first_name = strip_tags($rows['first_name']);
                      $attendee_last_name = strip_tags($rows['last_name']);
                      $attendee_email = $rows['email'];
                      $attendee_enveloppe = $rows['enveloppe'];
                      $attendee_company = strip_tags($rows['company']);
                      $attendee_sender = strip_tags($rows['sender']);
  
                      error_log($ticket_id . ' ' . $ticket_price . ' ' . $email_attendee);
  
  
                      /**
                       * Create the order
                       */
                      $order = new Order();
                      $order-&gt;first_name = $attendee_first_name;
                      $order-&gt;last_name = $attendee_last_name;
                      $order-&gt;enveloppe = $attendee_enveloppe;
                      $order-&gt;company = $attendee_company;
                      $order-&gt;sender = $attendee_sender;
                      $order-&gt;email = $attendee_email;
                      $order-&gt;order_status_id = config('attendize.order_complete');
                      $order-&gt;amount = $ticket_price;
                      $order-&gt;account_id = Auth::user()-&gt;account_id;
                      $order-&gt;event_id = $event_id;
  
                      // Calculating grand total including tax
                      $orderService = new OrderService($ticket_price, 0, $event);
                      $orderService-&gt;calculateFinalCosts();
                      $order-&gt;taxamt = $orderService-&gt;getTaxAmount();
  
                      if ($orderService-&gt;getGrandTotal() == 0) {
                          $order-&gt;is_payment_received = 1;
                      }
  
                      $order-&gt;save();
  
                      /**
                       * Update qty sold
                       */
                      $ticket = Ticket::scope()-&gt;find($ticket_id);
                      $ticket-&gt;increment('quantity_sold');
                      $ticket-&gt;increment('sales_volume', $ticket_price);
                      $ticket-&gt;event-&gt;increment('sales_volume', $ticket_price);
  
                      /**
                       * Insert order item
                       */
                      $orderItem = new OrderItem();
                      $orderItem-&gt;title = $ticket-&gt;title;
                      $orderItem-&gt;quantity = 1;
                      $orderItem-&gt;order_id = $order-&gt;id;
                      $orderItem-&gt;unit_price = $ticket_price;
                      $orderItem-&gt;save();
  
                      /**
                       * Update the event stats
                       */
                      $event_stats = new EventStats();
                      $event_stats-&gt;updateTicketsSoldCount($event_id, 1);
                      // $event_stats-&gt;updateTicketRevenue($ticket_id, $ticket_price);
  
                      /**
                       * Create the attendee
                       */
                      $attendee = new Attendee();
                      $attendee-&gt;first_name = $attendee_first_name;
                      $attendee-&gt;last_name = $attendee_last_name;
                      $attendee-&gt;email = $attendee_email;
                      $attendee-&gt;enveloppe = $attendee_enveloppe;
                      $attendee-&gt;company = $attendee_company;
                      $attendee-&gt;sender = $attendee_sender;
                      $attendee-&gt;event_id = $event_id;
                      $attendee-&gt;order_id = $order-&gt;id;
                      $attendee-&gt;ticket_id = $ticket_id;
                      $attendee-&gt;account_id = Auth::user()-&gt;account_id;
                      $attendee-&gt;reference_index = 1;
                      $attendee-&gt;save();
  
                      if ($email_attendee == '1') {
                          $this-&gt;dispatch(new SendAttendeeInvite($attendee));
                      }
                  }
              };
          }
  
          session()-&gt;flash('message', $num_added . ' Attendees Successfully Invited');
  
          return response()-&gt;json([
              'status'      =&gt; 'success',
              'id'          =&gt; $attendee-&gt;id,
              'redirectUrl' =&gt; route('showEventAttendees', [
                  'event_id' =&gt; $event_id,
              ]),
          ]);
      }
  </code></pre>
  
  <p>I want the duplicates datas to be skipped and new ones to be added.</p>
  
  <p>What i'm missing?</p>
  
  <p>Thank you!</p>