我正在制作一个包含两个表的Web应用程序:类和部分。我的迁移如下所示。班级Schema::create('classes', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps();});栏目Schema::create('sections', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->integer('class_id')->unsigned(); $table->foreign('class_id')->references('id')->on('classes'); $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users'); $table->timestamps();});在我的Blade文件中,我想显示所有类的按钮。当我单击该按钮时,它应该显示所有部分,其中部分表中的class_id是所选按钮的部分。我因为语法而陷入困境。我是Laravel的新手,但是我不知道如何针对按钮添加响应。我的控制器部分public function index(){ $sections = Section::all(); $class = Class::all(); $users = User::all(); return view('sections.index')->with('sections', $sections)->with('class', $class)->with('users', $users);}刀@foreach($classs as $cat) <button class="btn btn-info">{{$cat->title}}</button> //this shows all buttons with class name@endforeach<div class="box-body"> <table class="table table-responsive"> <thead> <tr> <th>Section Name</th> <th>Class</th> <th>Teacher</th> <th>Modify</th> </tr> </thead>如何在这些表下获取仅选定类别的所有部分?这是建议的代码,在其中进行了更改,单击按钮后没有得到数据。请告诉我该怎么办?我是否需要更换控制器@foreach($classs as $cat) <button class="btn btn-info class_btn" id="{{$cat->class_id}}">{{$cat->title}}</button> <div class="box-body" style="display:none" id="table_{{$cat->class_id}}"> <table class="table table-responsive"> <thead> <tr> <th>Section Name</th> <th>Class</th> <th>Teacher</th> <th>Modify</th> </tr> </thead> <tbody>
1 回答
- 1 回答
- 0 关注
- 229 浏览
添加回答
举报
0/150
提交
取消