We use the Laravel class Validatorto perform some basic validation in the array.
My array:
$employee['name']='name';
$employee['address']='address';
$employee['department']['department_name']='deptname';
$employee['department']['department_address']='deptaddress';
I have validation rules as shown below:
$rules = array(
'name'=> 'required',
'address' => 'required',
'department.department_name' => 'sometimes|required'
)
And custom posts as below:
$messages = array(
'name.required' => 'Employee Name is required',
'address.required' => 'Address is required'
'department.department_name.required' => 'Department name is required'
)
I'll use Validator::make($employee, $rules, $messages);
According to my rules, it department_nameshould be checked if and only if it is present in the array. But it Validatordoes not currently check department_namewhen it is present and empty. Any ideas what I can do wrong?
source
share