【发布时间】:2022-01-23 17:02:12
【问题描述】:
我正在使用 Laravel 8 开发一个项目,我需要在表单中创建一个动态下拉列表来创建类别。第一个下拉菜单必须显示商店,第二个下拉菜单应显示该商店的类别。我不知道我是否应该使用 javascript 或其他方式来执行此操作。
表格:
<label for="store_id">Store</label>
<select id="store_id" name="store_id" class="custom-select">
@foreach($stores as $store)
<option value="{{ $store->id}}">{{ $store->name}}</option>
@endforeach
</select>
<label for="parent_category">Parent Category</label>
<select id="parent_category" name="parent_category" class="custom-select">
</select>
类别表
| id | store_id | parent_category_id | name |
|---|
存储表
| id | name |
|---|
CategoryController.php
public function create()
{
$stores = Store::all();
$categories = Category::all();
$data= [
'stores ' => $stores ,
'categories ' => $categories
];
return view('category.create')->with($data);
}
【问题讨论】:
标签: javascript laravel dynamic html-select