使用Laravel Validator类对数组进行一些基本验证。
我的阵列:
$employee['name']='name';
$employee['address']='address';
$employee['department']['name']='deptname';
$employee['department']['address']='deptaddress';
我的验证规则如下:
$rules = array(
'name'=> 'required',
'address' => 'required'
)
自定义消息如下:
$messages = array(
'name.required' => 'Employee Name is required',
'address.required' => 'Address is required'
)
我将使用Validator::make($employee, $rules, $messages);
如何使用相同的规则和消息变量编写$employee[department]['name']
和$employee[department]['address']
的规则和消息?
答案 0 :(得分:8)
对嵌套数组使用点表示法:
department.name
department.address