Support the ongoing development of Laravel.io →
Validation
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

codeATbusiness Works like a charm. Thanks a lot :)

Last updated 1 year ago.
0

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>') }}  

Last updated 1 year ago.
0

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');

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.