我有我的产品选项,我希望将它们显示为下拉列表,让用户从中选择,这是我上次结果的截图
正如你所看到的,我的表格中有2个颜色的行和3个尺寸的行,我希望是1个颜色的行和1个尺寸的行,然后在下拉列表中选择颜色和尺寸。
这是我的刀片代码:
<div class="options">
<h3>options:</h3>
<table class="table table-bordered table-striped">
<tbody>
@foreach($product->suboptions as $option)
<tr>
<td style="width: 150px;">{{ $option->option->title }}</td> //this shows Color,Sizes, etc.
<td class="text-left">
<select name="" id="">
<option value="{{$option->id}}">{{$option->title}} - {{ number_format($option->price, 0) }}</option> //This shows options like Gray,Red, XL, etc.
</select>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
有什么想法吗?
这是我的控制器代码:
public function showproduct($slug) {
$product = Product::where('slug', $slug)->firstOrFail();
$images = DB::table('images')->where('imageable_id', '=', $product->id)->get();
$product->addVisit();
$arrivaltime = Carbon::now()->addWeekdays($product->arrivialin);
$mytime = Carbon::now();
$rates = $product->ratings()->orderby('id', 'desc')->get();
$random = Product::inRandomOrder()->limit(10)->get();
$discounts = Discount::where('product_id', '=', $product->id)->get();
return view('front.single', compact('product', 'images', 'arrivaltime', 'mytime', 'rates', 'random', 'discounts'));
}