0

my validation is working correctly. but didn't show any message. I mention the below.

in controller

$fields = collect([
    'monthly_fees',
    'admission',
    'due_advance',
    'session_fee',
    'library',
    'sports',
    'poor_funds',
    'fine',
    'reciept',
    'milad',
    'scout',
    'development',
    'registration',
    'f_tutorial',
    's_tutorial',
    't_tutorial',
    'f_exam',
    's_exam',
    't_exam',
    'labratory',
    'transport',
    'syllabus',
    'certificate',
    'testimonial',
    'generator',
    'extra'
]);

$rules = $fields->mapWithKeys(function ($field) use ($fields) {
    return [
        $field => 'required_without_all:' . $fields->reject(function ($item) use ($field) {
                return $item == $field;
            })->implode(',')
    ];
})->toArray();

$this->validate($request, $rules);

in views

@if (count($errors) > 0)
    <div class="alert alert-danger">
        <ul class="text-center">
            @foreach($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

I also use these lines of codes in the controller but didn't work.

if($this->validate()->fails()) {
   return redirect()->back()->with('error','Please Input minimum 1 field...');
}

I want to do minimum 1 field is required. I have 26 input fields. I always use these codes for single use. but this time want to validate minimum One field required. These codes validate the required but didn't show any messages though I mentioned the errors in blade. can you please help me with these errors? thanks in advance.

tariqul anik
  • 314
  • 6
  • 24
  • Are you using Web middleware in the routes? Check out this link https://stackoverflow.com/questions/36784253/laravel-5-2-validation-error-not-appearing-in-blade – Mohammad.Kaab May 07 '20 at 10:59
  • it doesn't make any sense. I didn't use web routes. But I use my custom middleware. for login validation. what should I do now to show the messages? – tariqul anik May 07 '20 at 15:18
  • my laravel version is 6.18 but your ans is for 5.27. here he works inside `http/routes.php`. but I have no files named like this. – tariqul anik May 07 '20 at 15:38

1 Answers1

0

I solved my problems. here i used $this->vatidate(...); it was wrong for me. then I used Validator package and returns a custom message with redirect if fails. then it works.

tariqul anik
  • 314
  • 6
  • 24