Am using the Laravel Validator
class to do some basic validation on an array.
My array :
$employee['name']='name';
$employee['address']='address';
$employee['department']['department_name']='deptname';
$employee['department']['department_address']='deptaddress';
I have the validation rules as below:
$rules = array(
'name'=> 'required',
'address' => 'required',
'department.department_name' => 'sometimes|required'
)
And the custom messages as below :
$messages = array(
'name.required' => 'Employee Name is required',
'address.required' => 'Address is required'
'department.department_name.required' => 'Department name is required'
)
I will use Validator::make($employee, $rules, $messages);
As per my rules, department_name
should be validated if and only if it is present in the array. But currently the Validator
is not validating department_name
when its present and blank. Any ideas what I might be doing wrong?