4

I am using Laravel 6.13.1.

I have the following validation

$validator = Validator::make($request->all(), [
    'name' => 'required|max:100',
    'email' => 'required|email',
    'mobile_number' => 'required',
    'date_of_birth' => 'required',
    'address' => 'required',
    'category' => 'required',
    'other_category' => 'required_if:category,==,Others',
    'sub_caste' => 'required',
    'photo' => 'required',
    'status' => 'required|integer',
    'father_name' => 'required',
    'father_occupation' => 'required',
]);


if ($validator->fails()) {
    return back()->withErrors($validator)->withInput();                    
}

It has 12 rules and it works. If I add one more rule then the validator stops working.

{{$errors}} gives an empty array in the view file.

Edit 1: The validation with 12 rules shows all error messages, but if I add one more validation like

$validator = Validator::make($request->all(), [
    'name' => 'required|max:100',
    'email' => 'required|email',
    'mobile_number' => 'required',
    'date_of_birth' => 'required',
    'address' => 'required',
    'category' => 'required',
    'other_category' => 'required_if:category,==,Others',
    'sub_caste' => 'required',
    'photo' => 'required',
    'status' => 'required|integer',
    'father_name' => 'required',
    'father_occupation' => 'required',
    'mother_name' => 'required',         
]);

then no error messages. {{$errors}} is an empty array.

In my view, I am using the following code to list errors

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

Edit 2: I tried the same validation on Laravel 5.5 and it works well as indented.

18
  • I don't think I've ever seen a limit. How does it stop working? Can you show the validator with 13 rules?
    – aynber
    Jan 31, 2020 at 18:37
  • could you add the last rule that stops your validation ?
    – Joseph
    Jan 31, 2020 at 18:39
  • @anber stops working means, no error messages.
    – Joyal
    Jan 31, 2020 at 18:42
  • @joseph I added the last rule.
    – Joyal
    Jan 31, 2020 at 18:42
  • could you try to stop the redirect method and try to return only with error like this return $validator->errors(); to see what happens here
    – Joseph
    Jan 31, 2020 at 18:48

2 Answers 2

4

I was facing the same problem, and found somewhere that maybe this is caused by the size of error messages. I've changed the SESSION_DRIVER env option from "cookie" to "file" and it worked!

0

I don't think that it has a limit, However you can create a request and put all your validation on it like that:

php artisan make:request UserRequest

You can check out this link Form Request Validation

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.