title: Uploading CSV contents to database using Laravel
body: <p>I am trying to upload a CSV file with one row using Laravel. Its content is to be stored in the already made database (MySQL) which I have, however I am having great difficulty in doing so. </p>
  
  <p>Here is my form:</p>
  
  <pre class="lang-twig prettyprint-override"><code>    &lt;center&gt;
      &lt;form action="/csvfileupload" method="post"&gt;
      &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
      &lt;h4&gt;&lt;label&gt; Please Select File (CSV only):&lt;/label&gt;
      &lt;input type="file" name="csvfile"/&gt;&lt;/h4&gt;
      &lt;h4&gt;&lt;input type="submit" name="upload" value="Upload"/&gt;&lt;/h4&gt;
      &lt;/form&gt;
      {{ csrf_field() }}
      &lt;/center&gt;
  </code></pre>
  
  <p>Here is my route:</p>
  
  <pre><code>    Route::post('/csvfileupload','Controller@csvfileupload');
  </code></pre>
  
  <p>Here is my controller: </p>
  
  <pre class="lang-php prettyprint-override"><code>function csvfileupload(Request $req)
  {
      $title = $req-&gt;input('title');
      $address = $req-&gt;input('address');
      $Date = $req-&gt;input('Date');
      $intro = $req-&gt;input('intro');
      $mainbody = $req-&gt;input('mainbody');
      $paragraph = $req-&gt;input('paragraph');
      $footer = $req-&gt;input('footer');
  
      $data =
      array('title'=&gt;$title,'address'=&gt;$address,'Date'=&gt;$Date,'intro'=&gt;$intro,
     'mainbody'=&gt;$mainbody,'paragraph'=&gt;$paragraph,'footer'=&gt;$footer);
      DB::table('template')-&gt;update($data);
  
      echo "Success";
  }
  </code></pre>
  
  <p>CSV file: </p>
  
  <pre class="lang-csv prettyprint-override"><code>title,address,Date,intro,mainbody,paragraph,footer
  Module Bro,"Hi,",2018-03-14,Attention all students!: This is very 
  important!,"Your results are out now on blackboard, you have received a 
  grade of:",Comments for your coursework are as follows if you have any 
  concerns feel free to contact me at any time.,"Yours Truly, best tutor ever. 
  helen d."
  </code></pre>
  
  <p>I want to store them in the database, but how can I do that?</p>