title: Laravel: How to save on database from dynamic jquery checkbox
body: <p>Good day everyone!</p>
  <p>I have the next issue on my Laravel project</p>
  <p>I have a dynamic checkbox that I do it with jquery, my issue is when I try to save on my database, this save me all the values from all the checkbox selected on different lines in one line, I use implode to save in the cell, but save me the same result on all the cells, the input text for &quot;medicamento&quot; and &quot;dosis&quot; working correctly, but the checkbox &quot;cuando1&quot; is not working.</p>
  <p><strong>Jquery Script</strong></p>
  <pre><code>&lt;script id=&quot;document-template&quot; type=&quot;text/x-handlebars-template&quot;&gt;
          &lt;tr class=&quot;delete_add_more_item&quot; id=&quot;delete_add_more_item&quot;&gt;
              &lt;td style=&quot;width:300px;border: 5px solid transparent&quot;&gt;&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;medicamentos[]&quot; aria-describedby=&quot;medicamentos&quot; id=&quot;medicamentos&quot; placeholder=&quot;Medicamentos Recetados&quot;&gt;&lt;/td&gt;
              &lt;td style=&quot;width:100px;border: 5px solid transparent&quot;&gt;&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;dosis[]&quot; aria-describedby=&quot;dosis&quot; id=&quot;dosis&quot; placeholder=&quot;Dosis&quot;&gt;&lt;/td&gt;
              &lt;td style=&quot;width:50px;border: 5px solid transparent&quot;&gt;&lt;label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;cuando[]&quot; id=&quot;cuando1&quot; value=&quot;Mañana&quot;&gt;&lt;/label&gt;&lt;/td&gt;
              &lt;td style=&quot;width:50px;border: 5px solid transparent&quot;&gt;&lt;label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;cuando[]&quot; id=&quot;cuando2&quot; value=&quot;Tarde&quot;&gt;&lt;/label&gt;&lt;/td&gt;
              &lt;td style=&quot;width:50px;border: 5px solid transparent&quot;&gt;&lt;label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;cuando[]&quot; id=&quot;cuando3&quot; value=&quot;Noche&quot;&gt;&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-danger&quot;&gt;&lt;i class=&quot;fa fa-minus fa-2x removeaddmore&quot; style=&quot;cursor:pointer;color:white;&quot;&gt;&lt;/i&gt;&lt;/button&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
  
          $(document).on('click','#addMore',function(){
  
              $('.table').show();
              var source = $(&quot;#document-template&quot;).html();
              var template = Handlebars.compile(source);
  
              var data = {
                  medicamentos: medicamentos,
                  dosis: dosis,
                  cuando1: cuando1,
                  cuando2: cuando2,
                  cuando3: cuando3,
              }
  
              var html = template(data);
              $(&quot;#addRow&quot;).append(html)
          });
  
          $(document).on('click','.removeaddmore',function(event){
              $(this).closest('.delete_add_more_item').remove();
          });
      &lt;/script&gt;
  </code></pre>
  <p><strong>Controller.php</strong></p>
  <pre><code>$number = count($request-&gt;medicamentos);
      for ($i=0; $i &lt; $number; $i++) {
         
          $cuando1 = implode(', ', (array) $request-&gt;get('cuando'));
              $Medicamentos = new Medicamentos();
              $Medicamentos-&gt;idpaciente = $idpaciente;
              $Medicamentos-&gt;medicamentos = $request-&gt;medicamentos[$i];
              $Medicamentos-&gt;fecha = $hoy;
              $Medicamentos-&gt;dosis = $request-&gt;dosis[$i];
              $Medicamentos-&gt;cuando1 = $cuando1;
              $Medicamentos-&gt;save();
      }
  </code></pre>
  <p>Image of database,check the column &quot;cuando1&quot; with all the values</p>
  <p><a href="https://i.stack.imgur.com/Cbmd4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cbmd4.jpg" alt="Database with column &quot;cuando&quot;" /></a></p>
  <p>Image of my blade with the selected checkbox, see that the Selected Checkbox are the saved on all the rows in the database with the implode.</p>
  <p>I want to save for aspirina 1: Mañana, Tarde, for aspirina 2: Mañana and for aspirina 3: Noche</p>
  <ul>
  <li>M = &quot;Mañana&quot;</li>
  <li>T = &quot;Tarde&quot;</li>
  <li>N = &quot;Noche&quot;</li>
  </ul>
  <p><a href="https://i.stack.imgur.com/9UcFW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9UcFW.jpg" alt="enter image description here" /></a></p>
  <p>I appreciate your help</p>