Good Morning...I am trying to update the data in table using ajax, while passing the data to controller using id, ID preview is showing NULL and so not able to update the data in Table. I am trying to add new data in one table and at same time update data in another table using same ajax... Ajax -
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).on('click', '#footer_addnewinspectiondata_button', function() {
$.ajax({
type: 'put',
url: '/addbuffaloinspectiondata',
dataType: 'json',
data: {
'buffaloID': $('#buffaloID').val(),
'inspectiondate': $('#inspectiondate').val(),
'pregnantstatus': $('#pregnantstatus').val(),
'healthstatus': $('#healthstatus').val(),
'weight': $('#weight').val(),
'height': $('#height').val(),
'weeklytika': $('#weeklytika').val(),
'monthlytika': $('#monthlytika').val(),
'inspection': $('#inspection').val(),
'inspectionby': $('#inspectionby').val(),
'inspectionnote': $('#inspectionnote').val(),
},
success: function(data) {
console.log(data);
},
error: function(e) {
console.log(e);
}
});
});
Web.php File
Route:: put('/addbuffaloinspectiondata',
[viewbuffaloController::class,'addbuffaloinspectiondata'])->name('addbuffaloinspectiondata');
Controller File -
public function addbuffaloinspectiondata(Request $req)
{
// add new data in buffaloinspection table for Buffalo ID
$newdata = new buffaloinspectiondata;
$newdata->buffaloID = $req->buffaloID;
$newdata->inspectiondate = $req->inspectiondate;
$newdata->weight = $req->weight;
$newdata->height = $req->height;
$newdata->pregnant = $req->pregnantstatus;
$newdata->health = $req->healthstatus;
$newdata->weeklytika = $req->weeklytika;
$newdata->monthlytika = $req->monthlytika;
$newdata->inspection = $req->inspection;
$newdata->inspectionby = $req->inspectionby;
$newdata->inspectionnote = $req->inspectionnote;
// update data in BuffaloDATA Table
$updatedata = buffalodata::find($req->buffaloID);
$updatedata->weight = $req->get('weight');
$updatedata->height = $req->get('height');
$newdata->save ();
$updatedata->save ();
return response()->json([$newdata,$updatedata],200);
}
Did i miss something or doing wrong in code... Thanks in Advance.


