我有一些代码
$validator->after(function ($validator) {
var_dump($request->input('answer'));
if (true) {
$validator->errors()->add('Question', 'The answer is not correct!');
}
});
但是我遇到了需要向下传递$ request-> input('answer')的问题。它给我一个错误,未定义$ request。我该怎么办?
答案 0 :(得分:0)
public function contact(Request $request) {
$validator = Validator::make($request->all(), [
'id' => 'required',
'boat' => 'required',
'name' => 'required',
'answer' => 'required',
'email' => 'required|email',
'message' => 'required'
]);
if ((int)$request->input('answer') != $request->session()->get('contact-seller-answer')) {
}
$validator->after(function ($validator, **$request**) {
var_dump($request->input('answer'));
if (true) {
$validator->errors()->add('Question', 'The answer is not correct!');
}
});
if ($validator->fails()) {
return redirect('ad/'.$request->input('id').'/'.$request->input('boat').'#form')
->withErrors($validator)
->withInput($request->all());
}
}