Laravel 4调用未定义的方法Illuminate\Database\Eloquent\Collection :: links() [英] Laravel 4 Call to undefined method Illuminate\Database\Eloquent\Collection::links()
本文介绍了Laravel 4调用未定义的方法Illuminate\Database\Eloquent\Collection :: links()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在名为 学习的书中实现代码Laravel 4应用程序开发 。
I tried to implement codes in the book entitled "Learning Laravel 4 Application Development".
一个简单的CRUD应用程序,如下所示,
A simple use CRUD app as following,
控制器
$users = User::all();
return View::make('users.index', compact('users'));
查看
<!--an simple table ...-->
<div class="pagination">
{{ $users->links() }}
</div>
它显示了一个错误:
调用未定义的方法Illuminate\Database\Eloquent\Collection :: links()
有人可以给我提示吗?。
Could someone give me an hint?.
推荐答案
您正在使用分页,因此 User :: all()
无效,因为您要让Eloquent返回所有记录而不分页。请参见分页用法。
You are using pagination, so User::all()
won't work because you are asking Eloquent to return all records without pagination. See Pagination Usage.
您需要更改
$users = User::all();
到
$users = User::paginate(10);
很明显,您可以将每页所需的记录数更改为10。
Obviously you can change 10 to the number of records per page you want.
这篇关于Laravel 4调用未定义的方法Illuminate\Database\Eloquent\Collection :: links()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文