samedi 17 juillet 2021

Integrity constraint violation: 1048 Column 'cd_id' cannot be null in laravel

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'cd_id' cannot be null (SQL: insert into commvendordata (new_date, cd_id, cn_id, unit_id, vender1, vender2, vender3, vender4) values (07/17/2021, ?, ?, ?, ?, ?, ?, ?))

how remove this error using laravel

form or blade screenshot

<form action="" method="POST" class="shadow-lg p-4 w-f">
                    @csrf
                    <div class="modal-date">
                        <label>Select Date:&emsp;&emsp;</label>
                        <input type="text" name="new_date" placeholder="Select Price Date" class="getdate"/>
                        <button type="button" name="loadform" class="btn btn-warning load-form">Load Form</button>

                    </div>
                  <div class="data" style="display:none;">
                    <table class="table table-bordered" id="table">
                        <thead class="bg-success">
                            <tr>
                                <th scope="col" class="td-size">CCode</th>
                                <th scope="col" class="td-size">CName</th>
                                <th scope="col" class="td-size">CUnits</th>
                                <th scope="col" class="td-size">Vendor 1</th>
                                <th scope="col" class="td-size">Vendor 2</th>
                                <th scope="col" class="td-size">Vendor 3</th>
                                <th scope="col" class="td-size">Vendor 4</th>
                            </tr>
                        </thead>
                        
                            <tr id="template">

                                    <td><input type="text" name="ccode[]" class="td-size"></td>
                                    <td><input type="text" name="cname[]" class="td-size"></td>
                                    <td><input type="text" name="cunit[]" class="td-size"></td>
                                    <td><input type="text" name="vendor1[]" class="td-size"></td>
                                    <td><input type="text" name="vendor2[]" class="td-size"></td>
                                    <td><input type="text" name="vendor3[]" class="td-size"></td>
                                    <td><input type="text" name="vendor4[]" id="addrow" class="td-size"></td>
                            </tr>
                        
                    </table>
                  </div>
                  <div class="modal-footer">
                  <button type="submit" name="commdatasavebtn" class="btn btn-success">Save</button>
                </div>
                </form>

controller screenshot

function commvendordata(Request $request){

$cvendordata = new commvendordata;

$new_date = $request->new_date;
$ccode = $request->ccode;
$cname = $request->cname;
$cunit = $request->cunit;
$vender1 = $request->vendor1;
$vender2 = $request->vendor2;
$vender3 = $request->vendor3;
$vender4 = $request->vendor4;
    for($i=0; $i<count($ccode); $i++) {
            $commdata = [
                'new_date'  => $new_date,
                'cd_id'     => $ccode[$i],
                'cn_id'     => $cname[$i],
                'unit_id'   => $cunit[$i],
                'vender1'   => $vender1[$i],
                'vender2'   => $vender2[$i],
                'vender3'   => $vender3[$i],
                'vender4'   => $vender4[$i]
            ];
            DB::table('commvendordata')->insert($commdata);
    }
    Session::put('Success',"Save Data Successfully...!");
    return back();

}

database screenshot enter image description here

error screenshot enter image description here

enter image description here

form screenshots enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire