here is controller method for insert data
public function addTeacher(Request $request)
{
$this->validate($request, [
'teacher_id' => 'required|min:1',
'name' => 'required|min:2',
'address' => 'required|min:3',
'cnic' => 'required|min:13',
'phone_no' => 'required|min:11',
'email' => 'required|email|unique:teachers',
'password' => 'required|confirmed|min:6',
'dept_id' => 'required|min:1'
]);
Teacher::create($request->except('_token'));
return redirect('admin/showTeachers');
}
here is Model
class Teacher extends Authenticatable
{
protected $primaryKey = 'teacher_id';
public $incrementing = false;
protected $fillable = [
'teacher_id',
'name',
'address',
'cnic',
'phone_no',
'email',
'password',
'dept_id',
];
}
i am getting this error (SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails)
i have data in department table but still getting this error