【问题标题】:Laravel 5.3 : Sending back array after validation gives errorLaravel 5.3:验证后发回数组会出错
【发布时间】:2017-08-05 17:45:23
【问题描述】:

我的看法是

<input type="text" name="color[]" value="{{ old('color') }}" placeholder="Enter Color">
<input type="text" name="price[]" value="{{ old('price') }}" placeholder="Enter Price">

并且由于价格和颜色是一个数组,因此在验证后尝试发回数组的值会出错。

$validator = Validator::make($request->all(), $rules, $messages);  

if ($validator->fails()) {
    return redirect('rate/create')
    ->withErrors($validator)
    ->withInput();

这里 withInput() 报错。错误如下:

htmlspecialchars() expects parameter 1 to be string, array given (View: /Users/.../www/abc/resources/views/abc/create.blade.php).

如何在验证后将该错误发送给查看。我也需要验证这个数组。谢谢你

【问题讨论】:

    标签: php arrays laravel validation laravel-5.3


    【解决方案1】:

    应该是

    <input type="text" name="color[]" value="{{Input::old('color') }}" placeholder="Enter Color">
    <input type="text" name="price[]" value="{{Input::old('price') }}" placeholder="Enter Price">
    

    我已将old 更改为Input::old

    这是server side validation 的示例文档链接

    我希望这会奏效。

    【讨论】:

    • 抱歉,这不是我想要的。我希望在验证失败时将该颜色和价格数组传递给我的视图。 @Swapper
    • dd 在方法中加载该视图并检查是否正在获取
    猜你喜欢
    • 2017-10-16
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    相关资源
    最近更新 更多