分页HTML表

在下表中,我把每个学生放在你属于表的老师之下。现在,我想要分页显示在桌下的学生。所以如果第一个选项卡有10个学生,我可以分页到5.分页HTML表

目前,我的代码没有做我想做的事情。我如何实现这一目标?

PS:我知道语法会怎样,如果我想分页老师喜欢teachers->links()

控制器

$teacher = Teacher::where('branch_id', Auth::user()->branch_id); 

return view('create',compact('teachers));

HTML

<div class="nav-tabs-custom" id="tabs"> 

<ul id="myUL" class="nav nav-tabs">

@foreach($teachers as $teacher)

<li ><a href="#tab_{{ $teacher->id }}" data-toggle="tab" >{!!$teacher->name!!}</a></li>

@endforeach

</ul>

<div class="tab-content">

@foreach($teachers as $key => teacher)

<div class="tab-pane" id="tab_{{ $teacher->id }}">

<table class="table" id="tables">

<thead>

<tr>

<th></th>

<th colspan="5"></th>

<th></th>

</tr>

</thead>

<tbody>

@foreach($teacher->students as $std)

<tr>

<td></td>

<td>{{$std->name }}</td>

<td></td>

</tr>

@endforeach

</tbody>

</table>

{{$teacher->stduents->links()}}

</div>

@endforeach

</div>

</div>

回答:

你确实有一对夫妇语法错误,我想象他们的错字,但以防万一:$teacher在控制器应该是复数,@foreach($teachers as $key => teacher)值应为$teacher{{$teacher->stduents->links()}}大概应该是学生

在你的控制器,你可以这样做:

$teachers = Teacher::where('branch_id', Auth::user()->branch_id)->get(); 

foreach ($teachers as $teacher) {

$students = $teacher->students()->paginate(5);

}

return view('index', compact('teachers', 'students'));

而在你的看法:

 @foreach($students as $std) 

<tr>

<td></td>

<td>{{$std->name }}</td>

<td></td>

</tr>

@endforeach

</tbody>

</table>

{{$students->links()}}

这也应该工作。在您的教师型号:

public function paginateStd() 

{

return $this->students()->paginate(5);

}

而在你的看法:

@foreach($teacher->paginateStd() as $std) 

<tr>

<td></td>

<td>{{$std->name }}</td>

<td></td>

</tr>

@endforeach

</tbody>

</table>

{{$teacher->paginateStd()->links()}}

以上是 分页HTML表 的全部内容, 来源链接: utcz.com/qa/261796.html

回到顶部