表单提交验证不通过

问题

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

表单

    <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'],
        ];
    }
}
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 3

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

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

5年前 评论

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

5年前 评论
JensonWang

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

5年前 评论

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