Search code examples
phparrayslaravellaravel-6laravel-validation

Solved: Laravel 6 Can't get error message of validation of array input (input with same name) with other inputs if total input are greater than 85


I am using laravel 6.10 on windows 7 (x64) wamp server (v 3.2.2.2).

I am validating 1 array input and 2 text inputs. I get validation error message in blade if array size is 84 or less than that. If i increase the array size to 85. I don't get any error message.

The validation function work as it redirect back if input is invalid but it doesn't show error message if array size is greater than 85. If input is valid, then no problem

here is blade

@if ($errors->any())
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif          
   <div class="flex-center position-ref full-height">
        <form method="post" action="{{url('form')}}" id="infoForm" >
            @csrf
            <input type="text" class="form-control" name="name" placeholder="Section A" value="{{ old('name') }}">
            <input type="text" class="form-control" name="king" placeholder="Section A" value="{{ old('king') }}">
            @for($i=0;$i<85;$i++)
                <input type="hidden" name="test[]" value="{{$i}}">
            @endfor
            <button type="submit">Submit</button>
        </form>         
    </div>

Controller

 public function store(Request $request)
{
    $validatedData = $request->validate([
        'name' => 'bail|required',
        'king' => 'bail|required',
        'test.*' => 'required'
    ]);
    dd('test');
    return redirect('form')->with('success', 'Information has been added');    
    
}

@dd(session()->all()) Result in blade if array size is less than 84

array:4 [▼
  "_token" => "s3kZaeGmEI9C7lNcH8mDLnzU0KNcXkO9luPeIzQa"
  "_flash" => array:2 [▶]
  "_old_input" => array:4 [▶]
  "errors" => Illuminate\Support\ViewErrorBag {#246 ▶}
]

@dd(session()->all()) Result in blade if array size is great than 84

array:3 [▼
  "_token" => "HjFH5QBSYaqnBAx8QG6PEGiIObueWYr6AjpVPolZ"
  "_previous" => array:1 [▶]
  "_flash" => array:2 [▶]
]

Is this a problem related to web server or related to laravel. Kindly help me to solve it. Here is the project on github https://github.com/mhabib555/LaravelMultipleInputWithSameNameValidation


Solution

  • Check what you have for a session driver if it is a cookie as the default is on new projects, add this to your .env file

    SESSION_DRIVER=file