【发布时间】:2019-07-16 06:52:00
【问题描述】:
如何在表格中添加每一行的行号?我使用了分页,但发现很难显示行数。在第 2 页,它应该从 6 开始,因为我的分页是每页 5。
编辑
还有如何在表格上方正确显示showing 1 to 5 of 2095这个词?
控制器
class SchoolController extends Controller
{
function index()
{
$q = Input::get('q');
if ($q != "") {
$schools = LibSchool::where('school_name', 'LIKE', '%' . $q . '%')
->orWhere('school_id', 'LIKE', '%' . $q . '%')
->orWhere('address', 'LIKE', '%' . $q . '%')
->orWhere('school_head', 'LIKE', '%' . $q . '%')
->orWhere('level', 'LIKE', '%' . $q . '%')
->orderBy('school_name', 'asc')
->with('libdistrict')
->with('libdistrict.libdivision')
->paginate(5)->appends('q', $q);
} else {
$schools = LibSchool::with('libdistrict')
->orderBy('school_name', 'asc')
->with('libdistrict.libdivision')
->paginate(5);
}
return view('schools.index')->with('data', ['schools' => $schools, 'q' => $q]);
}
}
查看
<div class="card-body">
Showing 1 to 15 of {{$data['schools']->total()}}
<table class="table table-hover table-bordered table-striped">
<tr>
<th>#</th>
<th>Division</th>
<th>District</th>
<th>School ID</th>
<th>School NAME</th>
<th>Address</th>
<th>School Head</th>
<th>Level</th>
</tr>
@if($data['schools']->total() > 0)
@foreach($data['schools'] as $school)
<tr>
<td></td>
<td>{{ $school->libdistrict ? $school->libdistrict->libdivision->div_name : 'N/A' }}</td>
<td>{{ $school->libdistrict ? $school->libdistrict->district_name : 'N/A' }}</td>
<td>{{$school->school_id}}</td>
<td>{{$school->school_name}}</td>
<td>{{$school->address}}</td>
<td>{{$school->school_head}}</td>
<td>{{$school->level}}</td>
</tr>
@endforeach
@else
<td colspan="7" class="text-danger">No records</td>
@endif
</table>
{{$data['schools']->links()}}
</div>
【问题讨论】:
标签: laravel pagination