Please help me to solve my problem
Ok
Edit: You had just written the above text (without explaining what the problem is or providing code) when I wrote OK.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Please help me to solve my problem
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
and one more thing i have another table courses that is also dependent on department table and when i insert on courses table with same dept_id i cannot get any error
Please or to participate in this conversation.