I'm trying to pass a value on failed validation in Laravel.
I tried this, but couldn't get the output.
if ($validation->fails()) {
$errorflag=1;
return Redirect::back()->withInput()->withErrors($validation)->with('errorflag', $errorflag);
}
I tried to get this value in the view using just a isset() check
<?php
if(isset($errorflag)){
echo $errorflag;
}
?>
But I'm unable to get the output even though I made a validation error in the form. How can I do this?
No need for a flag or session param, withErrors
fills the variable $errors
and thus is detectable:
@if($errors->any())
// do something
@endif
In your blade do
@if(Session::has('errorflag'))
//do something
@endif