我试图验证每个将注册的用户,如果他们的用户名/员工编号存在于主列表中。
如果不存在,则显示错误。如果存在,注册将进入另一个验证
控制器:
return Validator::make(
[
'employeenumber' => 'required|max:9|unique:users|alpha_dash|exists:masterlist',
'name' => 'required',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|max:30|confirmed',
'password_confirmation' => 'required|same:password',
],
[
'employeenumber.exists' => trans('auth.EmployeeNumberNull'),
'employeenumber.unique' => trans('auth.EmployeeNumber'),
'employeenumber.required' => trans('auth.EmployeeNumberRequired'),
'name.required' => trans('auth.AccNameRequired'),
'email.required' => trans('auth.emailRequired'),
'email.email' => trans('auth.emailInvalid'),
'password.required' => trans('auth.passwordRequired'),
'password.min' => trans('auth.PasswordMin'),
'password.max' => trans('auth.PasswordMax'),
]
错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'employeenumber' in 'where clause' (SQL: select count(*) as aggregate from `employees` where `employeenumber` = 03-444555) {"exception":"[object] (Illuminate\Database\QueryException(code: 42S22):
我得到服务器错误时,注册员工编号不是在数据库上,而不是抛出一个错误。
我找到了解决方案,列应该在验证中声明
'employeenumber' => 'required|max:9|unique:users|alpha_dash|exists:masterlist',
应该
'employeenumber' => 'required|max:9|unique:users|alpha_dash|exists:masterlist,employeenumber',