我正在尝试在 Laravel 中传递一个失败验证的值。
我试过这个,但无法获得输出。
if ($validation->fails()) {
$errorflag=1;
return Redirect::back()->withInput()->withErrors($validation)->with('errorflag', $errorflag);
}
我试图仅使用 isset() 检查在视图中获取此值
<?php
if(isset($errorflag)){
echo $errorflag;
}
?>
但是即使我在表单中犯了验证错误,我也无法获得输出。我该怎么做?
不需要标志或会话参数,withErrors
填充变量$errors
,因此可以检测到:
@if($errors->any())
// do something
@endif
在你的刀片中做
@if(Session::has('errorflag'))
//do something
@endif