如何解决Laravel尝试访问类型为null的值的数组偏移量
尝试在控制器中访问类型为null的值的数组偏移量
foreach ($request->product_item_list as $xx)
echo $request->hidden_name_[$xx] . ' ' . $request->product_unit_price_[$xx] . ' ' . $request
->quantity_list_[$xx] . ' ' . $request->hidden_barcode_[$xx];
其中dd($ request-> product_item_list)喜欢
array:1 [▼
0 => "13"
]
dd($ request-> all())看起来
array:14 [▼
"_token" => "JuFDWGzK10dV00cwMaqgX4I9R7tbVLErJ11vxjYv"
"category_salesCoffee" => "6"
"hidden_name_12" => "alto"
"quantity_list_12" => null
"hidden_barcode_12" => "11120"
"product_unit_price_12" => null
"hidden_cost_12" => "14"
"product_item_list" => array:1 [▼
0 => "13"
]
"hidden_name_13" => "black"
"quantity_list_13" => "1"
"hidden_barcode_13" => "11130"
"product_unit_price_13" => "33"
"hidden_cost_13" => "14"
"product_count" => "2"
]
blade.PHP
@foreach ($products as $item)
<tr>
<td scope="row">{{ $item->id }}</td>
<td>
<input type="checkBox" name="product_item_list[]" id="product_item_list[]" value="{{$item->id}}" {{$item->quantity == 0 ? 'disabled' : ''}}>
</td>
<td id="product_name">{{$item->name}}</td>
<input type="hidden" name="hidden_name_{{ $item->id }}" id="hidden_name_{{ $item->id }}" value="{{$item->name}}">
<td>
<input type="number" name="quantity_list_{{ $item->id }}" id="quantity_list_{{ $item->id }}" min="{{$item->quantity == 0 ? 0: 1}}" max="{{$item->quantity}}" onkeypress="return false" {{$item->quantity == 0 ? 'disabled' : ''}}>
</td>
<td>{{ $item->barcode }}
</td>
<input type="hidden" name="hidden_barcode_{{ $item->id }}" id="hidden_barcode_{{ $item->id }}" value="{{ $item->barcode }}">
<td>
<input type="text" name="product_unit_price_{{ $item->id }}" id="product_unit_price_{{ $item->id }}" {{$item->quantity == 0 ? 'disabled' : ''}}>
</td>
<td>
<input type="hidden" name="hidden_cost_{{ $item->id }}" id="hidden_cost_{{ $item->id }}" value="{{ $item->cost }}">
</td>
</tr>
@endforeach
解决方法
您没有输入数组。您有单独的输入,恰好恰好在其名称后附加了某种类型的标识符。因此,没有名为hidden_name_
的输入,而这正是您在请求中所要求的。
由于它们不是数组,您可以尝试使用它们的真实名称来拉出它们:
$request->input('hidden_name_'. $xx)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。