【发布时间】:2018-01-19 19:07:44
【问题描述】:
我需要帮助来循环我的产品选项,这就是我现在所拥有的:
我想要的只是为color 获取两行唯一的一个,为size 获取另一行,并且在每个前面的下拉列表中都有所有项目。
这是我的刀片代码:
<tbody>
@foreach($product->suboptions as $option)
<tr>
<td style="width: 150px;">{{ $option->option->title }}</td>
<td class="text-left">
<select name="" id="">
<option value="{{$option->id}}">{{$option->title}} - {{ number_format($option->price, 0) }}</option>
</select>
</td>
</tr>
@endforeach
</tbody>
更新
{dd($product->suboptions)}}我的 dd 结果
【问题讨论】:
-
你做了什么来调试这个?你试过
print_r($products->suboptions)吗?颜色和大小会出现多次吗? -
@BaileyParker 你是什么意思我做了什么?我分享了我有问题的代码。这是我的控制器代码
$product = Product::where('slug', $slug)->firstOrFail(); -
我的意思是 SO 不是来为您调试代码的。您应该在调试方面付出努力。在这种情况下,我建议在刀片循环之前使用
print_r($product->suboptions),这样您就可以查看子选项是否确实重复。 -
@BaileyParker 我分享了@987654332@结果
-
在这一行 {{ $option->option->title }} 选项方法在哪里引用(什么表)?
标签: php laravel laravel-blade