我在控制器中有一个这样的功能: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 回答
![?](http://img1.sycdn.imooc.com/533e4cde000148e602000200-100-100.jpg)
人到中年有点甜
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
![?](http://img1.sycdn.imooc.com/54584f8f00019fc002200220-100-100.jpg)
胡子哥哥
TA贡献1825条经验 获得超6个赞
您的错误在语句中。if
您应该说如果条件为真,请禁用。在你写的方式是一个,但你应该把它介绍为.echo
disable
simple string
html code
所以简而言之,你应该调用函数disable
echo
![?](http://img1.sycdn.imooc.com/54584cb50001e5b302200220-100-100.jpg)
江户川乱折腾
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
是循环增量
- 3 回答
- 0 关注
- 86 浏览
添加回答
举报
0/150
提交
取消