Please i am new to laravel, I want to insert form values into database, but i am getting this error.
"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'emp_id' cannot be null"
.
This is my laravel code.
private function saveEmployeeLeave(Request $request)
{
$empInfo = new AsEmployeeLeave();
$empInfo->emp_id = $request->emp_id;
$empInfo->department_id = $request->department;
$empInfo->application_time = Carbon::parse($request->application_time)->format('Y-m-d');
$empInfo->type = $request->selectedLeaveType;
$empInfo->date_from = $request->date_from;
$empInfo->date_to = $request->date_to;
$empInfo->comment = $request->comment;
$empInfo->requester_emp_id = $request->id;
$empInfo->requester_sign = $request->english_name;
$empInfo->approval_emp_id = $request->approval_emp_id;
$empInfo->approval_sign = $request->manager;
$empInfo->contact = $request->contact;
$empInfo->hours = $request->hours;
$empInfo->status = $request->status;
$empInfo->save();
return $empInfo;
}
This is my angular code for getting the data.
submitLeave(){
this.leaveList.emp_id= this.empData.id;
this.leaveList.department_id= this.leaveList.department_id;
if(!this.leaveList.selectedLeaveType){
this.snotifyService.error("Please select type of leave");
} else if(!this.leaveList.date_from){
this.snotifyService.error("Please select date from");
} else if(!this.leaveList.date_to){
this.snotifyService.error("Please select date to");
} else{
this.hrService.createLeave(this.leaveList).subscribe(data => {
if(data.status_code == 200){
this.snotifyService.success("leave added successfully");
this.modalService.dismissAll();
} else {
this.snotifyService.error(data.message);
}
},error=>{
this.snotifyService.error("Not able to load the data. Please reload project and try
again.");
});
}
}
The data service is returning this data, and it is this data that i want to store in the database with laravel
{
"status_code": 200,
"total_records": 1,
"message": "Success",
"errors": [],
"data": [
{
"employee_id": "ASM1060",
"department_id": "1",
"english_name": "francis",
"manager": "Luis Andres",
"reports_to": 12,
"paid_vacation": 15,
"used_vacation": 0,
"department": "IT",
"position_name": "IT Supervisor",
"status": null,
"leave_status": "Rejected",
"leave_eligible": 120,
"days_eligible": "15 days",
"remainder_eligible": 0,
"hours_eligible": 0,
"leavedays_eligible": "15 days 0 hour(s)",
"leave_balance": 120,
"days_balance": "15 days",
"remainder_balance": 0,
"hours_balance": 0,
"leavedays_balance": "15 days 0 hour(s)"
}
]
}
$request->emp_id
is null , you did not pass it to controller – sta