title: store array values with multiple select box using laravel
body: <p>I am trying to store array values by using for loop in laravel post function but the select box values are getting stored all together.</p>
  
  <p><strong>My View:</strong></p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;
   &lt;input type="text" class="form-control" autocomplete="off" name="particulars[]" &gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;select multiple name="event[]"&gt;
  &lt;option value=""&gt;--select--&lt;/option&gt;
  &lt;option value="E038|Event1"&gt;Event1&lt;/option&gt;
  &lt;option value="E039|Event2"&gt;Event2&lt;/option&gt;
  &lt;option value="E040|Event3"&gt;Event3&lt;/option&gt;
  &lt;option value="E041|Event4"&gt;Event4&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/table&gt; 
  </code></pre>
  
  <p><strong>my controller:</strong></p>
  
  <pre><code>for($i = 0; $i &lt; count($data['particulars']); $i++) {
  
          $c= new dailystatus(); // table name
          $c-&gt;particulars = $data['particulars'][$i];
  
          if(!empty($data['event'][$i])){
  
                  foreach($data['event'] as $eventname){
  
                      $repnamecode=$eventname;
                      $result=(explode('|', $repnamecode, 2));
                      $ecode[]=trim($result[0]);
                      $ename[]=trim($result[1]);
  
                      $evcode=implode($ecode, ',');
                      $evname=implode($ename, ',');
  
                  }else{
  
                      $evcode=0;
                      $evname=0;
  
                  }
  
          $c-&gt;event = $evcode;
          $c-&gt;evname=$evname;
          $c-&gt;save();
  
          }
  
  }
  </code></pre>
  
  <p>the values in database suppose to be stored like below in the image:</p>
  
  <p><a href="https://i.stack.imgur.com/08Hh4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/08Hh4.png" alt="enter image description here"></a></p>
  
  <p>But the values are getting doubled and storing like below:</p>
  
  <p><a href="https://i.stack.imgur.com/C4PaG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C4PaG.png" alt="enter image description here"></a></p>
  
  <p>So can you please suggest me how to avoid this duplication ? any help would be appreciated.</p>