title: Integrity constraint violation: 1048 Column 'cd_id' cannot be null in laravel
body: <p>SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cd_id' cannot be null (SQL: insert into <code>commvendordata</code> (<code>new_date</code>, <code>cd_id</code>, <code>cn_id</code>, <code>unit_id</code>, <code>vender1</code>, <code>vender2</code>, <code>vender3</code>, <code>vender4</code>) values (07/17/2021, ?, ?, ?, ?, ?, ?, ?))</p>
  <p>how remove this error using laravel</p>
  <p>form or blade screenshot</p>
  <pre><code>&lt;form action=&quot;{{route('auth.commvendordata')}}&quot; method=&quot;POST&quot; class=&quot;shadow-lg p-4 w-f&quot;&gt;
                      @csrf
                      &lt;div class=&quot;modal-date&quot;&gt;
                          &lt;label&gt;Select Date:&amp;emsp;&amp;emsp;&lt;/label&gt;
                          &lt;input type=&quot;text&quot; name=&quot;new_date&quot; placeholder=&quot;Select Price Date&quot; class=&quot;getdate&quot;/&gt;
                          &lt;button type=&quot;button&quot; name=&quot;loadform&quot; class=&quot;btn btn-warning load-form&quot;&gt;Load Form&lt;/button&gt;
  
                      &lt;/div&gt;
                    &lt;div class=&quot;data&quot; style=&quot;display:none;&quot;&gt;
                      &lt;table class=&quot;table table-bordered&quot; id=&quot;table&quot;&gt;
                          &lt;thead class=&quot;bg-success&quot;&gt;
                              &lt;tr&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;CCode&lt;/th&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;CName&lt;/th&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;CUnits&lt;/th&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;Vendor 1&lt;/th&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;Vendor 2&lt;/th&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;Vendor 3&lt;/th&gt;
                                  &lt;th scope=&quot;col&quot; class=&quot;td-size&quot;&gt;Vendor 4&lt;/th&gt;
                              &lt;/tr&gt;
                          &lt;/thead&gt;
                          
                              &lt;tr id=&quot;template&quot;&gt;
  
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;ccode[]&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;cname[]&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;cunit[]&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;vendor1[]&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;vendor2[]&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;vendor3[]&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;vendor4[]&quot; id=&quot;addrow&quot; class=&quot;td-size&quot;&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          
                      &lt;/table&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;modal-footer&quot;&gt;
                    &lt;button type=&quot;submit&quot; name=&quot;commdatasavebtn&quot; class=&quot;btn btn-success&quot;&gt;Save&lt;/button&gt;
                  &lt;/div&gt;
                  &lt;/form&gt;
  </code></pre>
  <p>controller screenshot</p>
  <p>function commvendordata(Request $request){</p>
  <pre><code>$cvendordata = new commvendordata;
  
  $new_date = $request-&gt;new_date;
  $ccode = $request-&gt;ccode;
  $cname = $request-&gt;cname;
  $cunit = $request-&gt;cunit;
  $vender1 = $request-&gt;vendor1;
  $vender2 = $request-&gt;vendor2;
  $vender3 = $request-&gt;vendor3;
  $vender4 = $request-&gt;vendor4;
      for($i=0; $i&lt;count($ccode); $i++) {
              $commdata = [
                  'new_date'  =&gt; $new_date,
                  'cd_id'     =&gt; $ccode[$i],
                  'cn_id'     =&gt; $cname[$i],
                  'unit_id'   =&gt; $cunit[$i],
                  'vender1'   =&gt; $vender1[$i],
                  'vender2'   =&gt; $vender2[$i],
                  'vender3'   =&gt; $vender3[$i],
                  'vender4'   =&gt; $vender4[$i]
              ];
              DB::table('commvendordata')-&gt;insert($commdata);
      }
      Session::put('Success',&quot;Save Data Successfully...!&quot;);
      return back();
  </code></pre>
  <p>}</p>
  <p>database screenshot
  <a href="https://i.stack.imgur.com/IgzkP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IgzkP.png" alt="enter image description here" /></a></p>
  <p>error screenshot
  <a href="https://i.stack.imgur.com/kZvNI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZvNI.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/McyVD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/McyVD.png" alt="enter image description here" /></a></p>
  <p>form screenshots
  <img src="https://i.stack.imgur.com/ZRMsk.png" alt="enter image description here" /></p>