html - 在刀片中水平对齐表格 td
问题描述
在我看来,我现在正试图让上学,有没有一种方法可以在不重复学生姓名的情况下水平对齐天数和状态:
这是我的刀片视图:
<table class="table table-hover table-bordered">
<tr>
<th>Student</th>
<th>Days</th>
<th>Status</th>
</tr>
@foreach($atnd as $atnds)
<tr>
<td>{{$atnds->lead->student_name}}</td>
<td>{{$atnds->days}}</td>
<td>{{$atnds->status}}</td>
</tr>
@endforeach
</table>
这是我的控制器
public function get_attendance(){
$atnd = Attendance::with(['level','lead'])->where(['level_id'=> 11])->get();
return view('attendance.index',compact('atnd'));
}
解决方案
您可以做的是按 student_id 分组,->get()
然后它将为您提供集合集合,然后在标题中显示日期和学生姓名(假设您对所有学生都有相同的日期)像这样
在控制器中
$atnds=Attendance::with(['level','lead'])->where(['level_id'=> 11])->get()->groupBy('student_id');
在视图中
<table class="table table-hover table-bordered">
<tr>
<th>Student</th>
@foreach($atnds->first() as $row)
<th>{{$row->days}}</th> //assuming you have dates same for all student
@endforeach
</tr>
@foreach($atnds as $group)
<tr>
<td>{{ $group->first()->lead->student_name}}</td>
@foreach($group as $row)
<td>{{$row->status}}</td>
@endforeach
</tr>
@endforeach
</table>
编辑
对于日期过滤器,您可以添加->whereMonth('days', '07')
条件
要在状态中显示下拉列表,您可以像这样添加它(替换 $row->status)
<table class="table table-hover table-bordered">
@if($atnds->count() > 0){
<tr>
<th>Student</th>
@foreach($atnds->first() as $row)
<th>{{$row->days}}</th>
@endforeach
</tr>
@foreach($atnds as $studentId => $group)
<tr>
<td>
{{ $group->first()->lead->student_name}}
</td>
@foreach($group as $index => $row)
<td>
<input type="hidden" name="student[{{ $studentId }}][{{ $index }}][day]" value = "{{ $row->days }}" />
<select name="student[{{ $studentId }}][{{ $index }}][status]">
<option {{ $row->status == 'P' ? 'selected' : '' }} value = "P">P</option>
<option {{ $row->status == 'L' ? 'selected' : '' }} value = "L">L</option>
</select>
</td>
@endforeach
</tr>
@endforeach
@else
<tr><td>No Record</td></tr>
@endif
</table>
推荐阅读
- python - 如何在 iPython 中查找父目录
- hyperledger-fabric - 链码实例化在超级账本结构中给出错误
- c++ - 使用与编译实际代码不同(更高)版本的 gcc 构建 strip/binutils 是否会导致任何问题?
- ios - 我正在寻求有关如何从 ios 应用程序实现linkedin 搜索工作/人员/内容的帮助
- angular - 如何在不触发订阅的情况下更改 queryParams?
- javascript - 正数范围 18-65 的正则表达式是什么?它必须只接受两位数
- html - 删除点击按钮周围的边框
- oracle-apex - 如何在同一个 oracle apex 应用程序中访问另一个模式表?
- clojure - Janusgraph - 如何使用空格进行不区分大小写的搜索 - textContainsRegex 不适用于空格
- c++ - 对符号“sodium_free”的未定义引用