为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel 5.8 - in_array给我错误:'htmlspecialchars()

Laravel 5.8 - in_array给我错误:'htmlspecialchars()

PHP
函数式编程 2022-08-19 10:46:03
我在控制器中有一个这样的功能:public function convert($id) {        $project        = ProjectMaster::findOrFail($id);        $items          = ProjectItem::all()->where('id_project_master', $id);        $deliveryOrder  = ProjectDeliveryOrder::where('id_project', $id)->first();        $itemsDO        = ProjectItemDeliveryOrder::all()->where('id_deliveryorder', $deliveryOrder->id)->pluck('id_item')->toArray();        return view('delivery-order-form-add', compact('project', 'value', 'items', 'itemsDO'));    }$items给我结果:{"5": {"id": 6,"id_project_master": 6,"name": "Item 1","qty": 2,"cost": "1,000,000","totalcost": "2,000,000","rate": "2,000,000","totalrate": "4,000,000","created_at": "2020-01-24 03:23:25","updated_at": "2020-01-24 03:23:25"},   "6": {       "id": 7,       "id_project_master": 6,       "name": "Item 2",       "qty": 2,       "cost": "2,500,000",       "totalcost": "5,000,000",       "rate": "4,000,000",       "totalrate": "8,000,000",       "created_at": "2020-01-24 03:23:25",       "updated_at": "2020-01-24 03:23:25"    }}并给我结果:$itemsDO[6]然后我有一个循环,在每个循环中,验证是否存在于刀片视图中,例如:in_array($this, $array)@foreach ($items as $item)<tr>    <td class="text-right"><input type="checkbox" class="form-check-input" name="id_item[]" value="{{ $item->id }}" @if(in_array($item->id, $itemsDO)) disabled @endif></td></tr>@endforeach此验证给我一个错误 。我写错了参数或没有在刀片Laravel上工作?htmlspecialchars() expects parameter 1 to be string, array givenin_array
查看完整描述

3 回答

?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

Blade 期望并处于单独的行上。您可以改用三元 IF:@if@endif


@foreach ($items as $item)

<tr>

    <td class="text-right"><input type="checkbox" class="form-check-input" name="id_item[]" value="{{ $item->id }}" {{ (in_array($item->id, $itemsDO)) ?  "disabled" : "" }}></td>

</tr>

@endforeach


查看完整回答
反对 回复 2022-08-19
?
胡子哥哥

TA贡献1825条经验 获得超6个赞

您的错误在语句中。if

您应该说如果条件为真,请禁用。在你写的方式是一个,但你应该把它介绍为.echodisablesimple stringhtml code

所以简而言之,你应该调用函数disableecho


查看完整回答
反对 回复 2022-08-19
?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

用这个代码解决:

<td class="text-right"><input type="checkbox" class="form-check-input" name="id_item[]" value="{{ $item->id }}" @if(in_array($items[$i]->id, $itemsDO)) disabled @endif></td>

$i是循环增量


查看完整回答
反对 回复 2022-08-19
  • 3 回答
  • 0 关注
  • 86 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信