Hi arulkumarpa, I haven't Laravel in front of but I think you could use the following lines:
$message = '';
$requiredCount = 0;
$arrayMessages;
foreach($errors->all() as $error){
if(preg_match('[required]', $error){
$requiredCount +=1;
}
}
if($requiredCount > 1){
$message = "Please, enter all the required fields";
}
You can adapt to your situation.
Hope it helps you.
codeATbusiness Works like a charm. Thanks a lot :)
There is an easier method for doing this. In your validation method just add a custom message for 'required' error.
Your code should look something like this.
$input = Input::all();
$rules = [
'email' => 'required | email',
'password' => 'required'
];
$message = ['required' => 'Please, enter all the required fields'];
$validator = Validator::make($input,$rules,$message);
In your view, don't iterate through all the errors. Instead grab the first error and echo it.
{{ $errors->first(null,'<div class="alert alert-danger">:message</div>') }}
Why not use use a error flash and a errors flash that way you can display errors if need he but in this scenario return Redirect::back()->withError(''You must fill in all requires fields');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community