PHP - Importing columns from uploaded CSV file to SQL database (Laravel 5.7) The goal is to upload the columns from the csv into the SQL Pro database. I am able to select the column names that have been uploaded from the csv file, the columns from the csv file are then uploaded into the option dropdown.  In return I need to submit the selections that have been selected from the options dropdown, into the database. I am writing this in PHP. What I have is definitely not correct.

PHP 

public function csvProcess(Request $request)
    {

        $contact = newContact();
        $contact-&gt;first_name = $rowProperties[$mapping['column_first_name']];
        $contact-&gt;last_name = $rowProperties[$mapping['column_last_name']];
        //$contact-&gt;newContact()-&gt;attach($first_name[$mapping['column_first_name']]);
        store(newContact()-&gt;where-&gt;$columnNames=$firstrow());
        $result = create($this(newContact()));

        $contact-&gt;save();
}


HTML

&lt;h1 class="mb-7 m-5 ml-6 font-bold text-2xl"&gt; Contact Fields&lt;/h1&gt;
  &lt;div v-for="field in requiredContactFields" class="p-8 -mr-6 -mb-8 flex flex-wrap" style="width:150px"&gt;
    &lt;label :for="field" type="select" name="field"&gt;{{field}}&lt;/label&gt;
    &lt;select :id="field" :name="field" v-model="mapping[field]"required&gt;
      &lt;option value=""&gt;Please Select&lt;/option&gt;
      &lt;option v-for="columnName in columnNames" :name="columnName" :value="columnName"  value=""&gt;{{columnName}}&lt;/option&gt;
    &lt;/select&gt;
  &lt;/div&gt;


Javascript

     submitFiles() 
        {
          //Form validation that will not allow a user to submit the form by upon the @click event 
          if(!this.$refs.csvFile.checkValidity())
          {
            return null;
          }
          let formData = new FormData();
          formData.append('file', this.file);
          axios.post('http://localhost:8080/api/contacts/upload-csv',
          formData,
          {
          headers: 
            {
              'Content-Type': 'multipart/form-data'
            }
          }
          )
          .then(function(response){
            console.log('SUCCESS!!');
            console.log(response);

          })
          .catch(function(response){
            console.log('FAILURE!!');
            console.log(response);

          })
        }




      } 
    }
    &lt;/script&gt;
I defined the fields that I wanted to be required first. Then, I defined a One-to-Many relationship between an account table and a contacts table where the contact id is the account's name in the account's table in the SQL database

        $account = new Account();
                $mapping = $request-&gt;$mapping;
                $account-&gt;name = $rowProperties[$mapping['account_name']];

                //One-To-Many Eloquent Relationship that links a table of Account Names in the Account's 
                //table to contact Account_ID's in the Contact tables  
                //$contact-&gt;id = $account-&gt;id;

                $account-&gt;save();

                $contact = new Contact();
                $contact-&gt;id = $account-&gt;id;
                $contact-&gt;contact_id = $rowProperties[$mapping['contact_account_name']];
                $contact-&gt;first_name = $rowProperties[$mapping['contact_first_name']];
                $contact-&gt;last_name = $rowProperties[$mapping['contact_last_name']]; 


    account = new Account();
                $account-&gt;name = $rowProperties[$mapping['account_name']];
                $this-&gt;account-&gt;hasMany('contact_account_names');
                //$accountid-&gt;contact_account_name
                $account-&gt;save();