- Controller
public function index()
{
$users = User::paginate('10'); // 分页函数
return view('user.index', ['users'=>$users]);
}
Return parameters to view the following three ways, all the same
return view('user.index', ['users'=>$users]);
return view('user.index', compact('users')); // 只要传键名
return view('user.index') -> with('users', $users);
- View files, use the bootstrap b4-card-head-foot, and b4-table-default
@extends('layouts.default')
@section('content')
<div class="card">
<div class="card-header">
用户列表
</div>
<div class="card-body">
<p class="card-text">
<table class="table">
<thead>
<tr>
<th>编号</th>
<th>昵称</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary btn-danger">删除</button>
<button type="button" class="btn btn-secondary btn-success">查看</button>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</p>
</div>
<div class="card-footer text-muted">
{{$users->links()}}
</div>
</div>
@endsection
Which {{$users->links()}}
is automatically generated page column