1 month ago

Laravel Excel - Import CSV data relationed to another table

Posted 1 month ago by felloz

I need to import some rows from a CSV file to a table, but this rows are relationed to another table to create the realtion of two registers. Thos relations are created by a field ID autoincremental.

I have 3 tables involved

  1. tbl_party Relationed tbl_party_employee,
  2. tbl_employee Relationed to tbl_party_employee,
  3. tbl_party_employee The table where i created the relations between 2 tables.

This is the method where my rows are setted to register

 public function model(array $row)
          return new Contact(
                    'user_id' => $this->userId,
                    'subscriber_email'     => $row[0],
                    'subscriber_name'      => $row[1],
                    'subscriber_lastname'  => $row[2],
                    'subscriber_phone'     => $row[3],
                    'whatsapp_number'      => $row[4],
                    'birth_date'    => $this->formatDateExcel($row[5]),
                    'custom_field1' => $row[6],
                    'custom_field1' => $row[7],
                    'custom_field1' => $row[8],
                    'custom_field4' => $row[9],

Any help to do this is appreciated.

Please sign in or create an account to participate in this conversation.