表单提交验证不通过

问题

表单提交到验证类时报错。
如果同时提交字符串类型和数组就报错。单提交字符串或数组就不报错。
问题出在哪里?
表单提交验证不通过

表单

    <form id="fleets" method="post" action="@if($fleet->id > 0) /fleets/ {{$fleet->id}} @else /fleets @endif">
                @csrf
                <input type="text" name="fleet_name">
                <br>
                <input type="text" name="car[]">
                <input type="text" name="car[]">
                <input type="text" name="car[]">
            </form>

验证类

    use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class FleetRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'fleet_name' => ['required'],
            'car.' => ['required'],
        ];
    }
}
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 3

我特意试了下,没问题啊,,Laravel 5.8

而且,数组元素验证是这样的 car.* => ...

4年前 评论

@largezhou 我就感觉很奇怪,只要同时提交字符串和数组就报错,单提交数组或者字符串就没问题

4年前 评论
JensonWang

错误提示是需要的是string(字符串),你给的是array(数组)

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!