孩子与另一个孩子有相同的child_birth_certificate_no
,这很好。但是同一个中心不能
因此,只有当child_birth_certificate_no
与同一中心中的另一个子级相同时,它才会失败
我面临的错误是:
message: "Class AppHttpRequestsChildRequest does not exist"
exception: "ReflectionException"
我的代码
public function rules(Request $request) {
$this->validate($request,array(
'child_birth_certificate_no' =>'required|unique:tbl_child,child_birth_certificate_no',
'centre_id'=> 'required|unique:tbl_child,centre_id',
));
return $to_validate;
}
如果这是自定义[Request
][1]中的rules
;我们称之为Child
[1] :https://laravel.com/docs/7.x/validation#creating-表单请求,然后删除Request $request
并尝试以下操作:
public function rules()
{
return [
'child_birth_certificate_no' =>'required|unique:tbl_child,child_birth_certificate_no',
'centre_id'=> 'required|unique:tbl_child,centre_id',
];
}
然后在控制器中使用以下变体:
<?php
...
use AppHttpRequestsChild;
...
public function store(Child $request)
{
// The incoming request is valid...
// Retrieve the validated input data...
$validated = $request->validated();
...
}