Laravel 4 调用未定义的方法 Illuminate\Database\Eloquent\Collection::links()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24605170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:47:16  来源:igfitidea点击:

Laravel 4 Call to undefined method Illuminate\Database\Eloquent\Collection::links()

laravellaravel-4crud

提问by user2837851

I tried to implement codes in the book entitled "Learning Laravel 4 Application Development".

我试图在题为学习 Laravel 4 应用程序开发的书中实现代码。



A simple use CRUD app as following,

一个简单的使用 CRUD 应用程序如下,

Controller

控制器

    $users = User::all();

    return View::make('users.index', compact('users'));

View

看法

<!--an simple table ...-->
<div class="pagination">
    {{ $users->links() }}
</div>

And it shows an error:

它显示一个错误:

Call to undefined method Illuminate\Database\Eloquent\Collection::links()

Call to undefined method Illuminate\Database\Eloquent\Collection::links()



Could someone give me an hint?.

有人可以给我一个提示吗?

回答by Unnawut

You are using pagination, so User::all()won't work because you are asking Eloquent to return all records without pagination. See Pagination Usage.

您正在使用分页,所以User::all()不会工作,因为您要求 Eloquent 返回所有没有分页的记录。请参阅分页使用

You need to change

你需要改变

$users = User::all();

to

$users = User::paginate(10);

Obviously you can change 10 to the number of records per page you want.

显然,您可以将 10 更改为您想要的每页记录数。