I have this array and I want to validate it in form request. But I'm having trouble validating it.
array:9 [
"user_type" => 5
"student" => array:2 [
"student_code" => "12-0033"
"student_number" => "10001-122"
]
"first_name" => "John"
"middle_name" => "Smith"
"last_name" => "Doe"
"email" => "[email protected]"
"password" => "a"
"password_confirmation" => "a"
"token" => ""
]
this is my validation code:
public function rules()
{
$user_type = $this->input('user_type');
$rules = [
'first_name' => 'required',
'middle_name' => 'required',
'last_name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required|confirmed',
];
if ($user_type == 5) {
// Validate student
$student_rules = [
'student.student_code' => 'required|unique:students',
'student.student_number' => 'required|unique:students',
];
$rules = array_merge($rules, $student_rules);
}
return $rules;
}
Everytime this is triggered I always get:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'student.student_code' in 'where clause' (SQL: select count(*) as aggregate from students where student.student_code = a)
It takes the 'student' from the 'student.student_code' as the table name.
What am I doing wrong? Newbie here.
I need some help. TIA