use*_*851 4 crud laravel laravel-4
我试图在题为" 学习Laravel 4应用程序开发 "的书中实现代码.
一个简单的使用CRUD应用如下,
调节器
$users = User::all();
return View::make('users.index', compact('users'));
Run Code Online (Sandbox Code Playgroud)
视图
<!--an simple table ...-->
<div class="pagination">
{{ $users->links() }}
</div>
Run Code Online (Sandbox Code Playgroud)
它显示一个错误:
Call to undefined method Illuminate\Database\Eloquent\Collection::links()
有人能给我一个提示吗?
你正在使用分页,所以User::all()
不会起作用,因为你要求Eloquent在没有分页的情况下返回所有记录.请参阅分页用法.
你需要改变
$users = User::all();
Run Code Online (Sandbox Code Playgroud)
至
$users = User::paginate(10);
Run Code Online (Sandbox Code Playgroud)
显然,您可以将10改为每页所需的记录数.