title: Checkbox in foreach loop in Laravel
body: <p>I have a foreach loop that has a checkbox in it.  I am not sure how to properly get that from the checkbox in the form over to the validation in the controller.  I have the following in my view:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;table class="table"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th scope="col"&gt;Select&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      @foreach($plans as $plan)
      &lt;tr&gt;
        &lt;td&gt;
          &lt;input type='checkbox' name='Plan {{$plan-&gt;{'Plan ID'} }}' class='form-check-input' value='true'
            @if(old($plan-&gt;{'Plan ID'},$plan-&gt;{'Plan ID'})=="true") checked @endif&gt;
        &lt;/td&gt;
        &lt;td&gt; {{$plan-&gt;{'Plan ID'} }}&lt;/td&gt;
        @endforeach
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I have the following in my controller:</p>
  
  <pre class="lang-php prettyprint-override"><code>$data = request()-&gt;validate ([
    'current' =&gt; '',
    'instructions' =&gt; '',
    'Plan 1' =&gt; '',
    'Plan 2' =&gt; '',
    'Plan 3' =&gt; '',
    'Plan 4' =&gt; '',
    'Plan 5' =&gt; '',
    'Plan 6' =&gt; '',
    'Plan 7' =&gt; '',
    'Plan 8' =&gt; '',
    'Plan 9' =&gt; '',
    'Plan 10' =&gt; '',
    'Plan 11' =&gt; '',
    'Plan 12' =&gt; '',
    'Plan 13' =&gt; '',
    'Plan 14' =&gt; '',
    'Plan 15' =&gt; '',
  ]);
  
  $plansubmission = PlanSubmission::find($id);
  //$plansubmission-&gt;update($data);
  
  $designs = MedicalDesignsToQuote::find($id);
  
  if($designs==null){
    $design = MedicalDesignsToQuote::create(['id'=&gt;$id]);
    $design-&gt;update($data);
  }
  else{
    $designs-&gt;update($data);
  </code></pre>
  
  <p>I do not want to use an array for the 'name' attribute</p>
  
  <p>Added this to controller:</p>
  
  <pre class="lang-php prettyprint-override"><code>$validator = Validator::make($request-&gt;all(), [
                      "list.*.id" =&gt; '', // Object exist validation 
                      "list.*.value" =&gt; '',
                      'current' =&gt; '',
                      'instructions' =&gt; '',
                  ]);
  
  $bodyContent = $request-&gt;getContent($validator);
  
  $plansubmission = PlanSubmission::find($id);
  // $plansubmission-&gt;update($data);
  
  $designs = MedicalDesignsToQuote::find($id);
  
  if($designs==null){
    $design = MedicalDesignsToQuote::create(['id'=&gt;$id]);
    // $design-&gt;update($data);
    $design-&gt;update($validator);
  }
  else{
    $designs-&gt;update($validator);
  }
  </code></pre>
  
  <p>I have the following columns in my table:</p>
  
  <pre><code>id
  current
  instructions
  Plan 1
  Plan 2
  Plan 3
  Plan 4
  Plan 5
  .....
  Plan 50
  </code></pre>
  
  <p>The user can select any or all of the 50 plan options with a checkbox.  If, for example, Plan 5 is selected, the value for this given row within the table will be 'True' for plan 5.  </p>
  
  <p>So, to persist the data, I would expect I need to do something like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$formData = $request-&gt;all();
  
  foreach ($formData['list'] as $planData) {
    MedicalPlanDesignToQuote::updateOrCreate(
      [$planData['id']] =&gt; $planData['value']],
    );
  }
  </code></pre>
  
  <p>If I had two columns called id and value, I suppose I could do this:</p>
  
  <pre class="lang-php prettyprint-override"><code>foreach ($formData['list'] as $planData) {
    MedicalPlanDesignToQuote::updateOrCreate(
      ['id' =&gt; $planData['id']],
      ['value' =&gt; $planData['value']]
    );
  }
  </code></pre>
  
  <p>Is there anyway I can do this with my table structure?</p>