我有学生,每届我有3节课2019、2020和2021。我的问题是如何验证此sql,其中,当我将2019升级到2020时,系统将不允许更新,因为数据已经存在。
让列session_id = 1然后student_id = 1(session_id = 1,值是2019)(student_id = 1,值是Student 1)
$this->validate($request, [
'promoted_session' => [
'required',
Rule::unique('sections')->ignore($id),
],
]);
您可以使用添加Additional Where Clauses:
$this->validate($request, [
'promoted_session' => [
'required',
Rule::unique('sections')->where(function ($query) use($id) {
return $query->where('sections', 1)->where('id' , '!=', $id);
})
],
]);