【问题标题】:Laravel array inputs - htmlentities() expects parameter 1 to be string, array givenLaravel 数组输入 - htmlentities() 期望参数 1 是字符串,给定数组
【发布时间】:2017-07-21 15:52:36
【问题描述】:

每当我将具有输入作为数组的表单相加时,我都会收到以下错误。

只有在我提交表单时才会出现问题。

我的输入数组是这样的:

【问题讨论】:

  • old('type') 是数组,您应该获取它的第一个值并手动填充输入。
  • name="type[]" 应该是 name="type" 如果只有一个。如果有多个,那么它是一个数组,你应该在提交后处理每个值。

标签: php arrays laravel-5.2


【解决方案1】:

您似乎将输入作为一种数组类型传递。 htmlentities() 仅适用于字符串类型。 这个

<td><input type="text" name="type[]" value="{{ old('type') }}" class="form-control"></td>

应该是

<td><input type="text" name="type" value="{{ old('type.0') }}" class="form-control"></td>

type.0 将只返回数组中的第一项。

【讨论】:

    猜你喜欢
    • 2017-09-23
    • 1970-01-01
    • 2016-10-26
    • 2016-04-30
    • 1970-01-01
    • 2017-01-11
    • 2017-05-17
    • 2015-04-30
    • 1970-01-01
    相关资源
    最近更新 更多