我在数据库中有3个不同的表,分别命名为productdetails,categories和subcategorydetails,同样,我有3个不同的控制器ProductdetailContoller,CategoryController和SubcategorydetailController] >分别。目前,我正在研究SubcategorydetailContoller的“视图”,它是subcategory.blade.php
`
@csrf <div class="form-group"> <select name="productid"> <option value="select product"> @foreach ($productdetail as $row) <option value="{{$row->ProductID}}"> {{$row->ProductType}} </option> @endforeach </option> </select> <select name="categoryid"> <option value="select category"> @foreach ($category as $row) <option value="{{$row->CategoryID}}"> {{$row->CategoryType}} </option> @endforeach </option> </select> <input type="text" name="subcategory"/> <input type="submit" value="add category"/> </div> </form> </div>`
现在我想创建动态相关的下拉列表,但是在进行此操作之前,我无法将第二个表的数据显示到第二个下拉列表中。
这是我在控制器中正在做的事情:
namespace App\Http\Controllers; use App\productdetail; use App\category; use App\subcategorydetail; use Illuminate\Http\Request; class SubcategorydetailController extends Controller { public function index() { $productdetails=productdetail::all(); return view('subcategory')->with('productdetail',$productdetails); //i wrote this in another class but i still didn't get the desired output $category=category::all(); return view('subcategory')->with('category', $category); } public function create() { } public function store(Request $request) { $data=new subcategorydetail(); $data->SubCatType=$request->subcategory; $data->CategoryID=$request->categoryid; $data->save(); return dd($data); //return view('subcategory'); }
在这里您可以看到,我的第二个下拉菜单没有显示任何内容
[[] [1] 1]:https://i.stack.imgur.com/ntzd1.png
我在数据库中有3个不同的表,分别命名为productdetails,categories和subcategorydetails,同样,我有3个不同的Controller ProductdetailContoller,CategoryController和...
HTML不提供与您的注释有关的功能。