简体   繁体   English

已解决:Laravel 6 如果总输入大于 85,则无法获取数组输入(同名输入)与其他输入的验证错误消息

[英]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).我在 Windows 7 (x64) wamp 服务器 (v 3.2.2.2) 上使用 laravel 6.10。

I am validating 1 array input and 2 text inputs.我正在验证 1 个数组输入和 2 个文本输入。 I get validation error message in blade if array size is 84 or less than that.如果数组大小为 84 或小于 84,我会在刀片中收到验证错误消息。 If i increase the array size to 85. I don't get any error message.如果我将数组大小增加到 85。我没有收到任何错误消息。

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如果输入无效,验证函数会重定向回来,但如果数组大小大于 85,则不会显示错误消息。如果输入有效,则没问题

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 @dd(session()->all()) 如果数组大小小于 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 @dd(session()->all()) 如果数组大小大于 84,则结果为刀片

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

Is this a problem related to web server or related to laravel.这是与 web 服务器相关的问题还是与 laravel 相关的问题。 Kindly help me to solve it.请帮我解决它。 Here is the project on github https://github.com/mhabib555/LaravelMultipleInputWithSameNameValidation这是 github 上的项目https://github.com/mhabib555/LaravelMultipleInputWithSameNameValidation

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检查你有什么会话驱动程序,如果它是一个 cookie,因为默认是在新项目中,将它添加到你的 .env 文件中

SESSION_DRIVER=file SESSION_DRIVER=文件

I think the problem might be value set for post_max_size in your php.ini .我认为问题可能是在您的php.inipost_max_size设置的值。 Make sure to update this with higher value.确保用更高的值更新它。

Also instead of:也代替:

'test.*' => 'required'

you probably want to add also:您可能还想添加:

'test' => ['array']

or maybe或者可能

'test' => ['array', 'required']

if there should be at least 1 item in test array to make sure test is an array.如果测试数组中至少应该有 1 个项目以确保test是一个数组。

Where your validation for the maximum array size ?您对最大数组大小的验证在哪里? Make sure you write it确保你写它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM