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

标签 laravel laravel-4 crud

我尝试实现题为"Learning Laravel 4 Application Development "书中的代码。

<小时/>

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

Controller

    $users = User::all();

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

查看

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

它显示一个错误:

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

<小时/>

有人可以给我提示吗?

最佳答案

您正在使用分页,因此 User::all() 将不起作用,因为您要求 Eloquent 返回所有不带分页的记录。请参阅Pagination Usage .

你需要改变

$users = User::all();

$users = User::paginate(10);

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

关于Laravel 4 调用未定义的方法 Illuminate\Database\Eloquent\Collection::links(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24605170/

相关文章:

laravel - WAMP + Composer + Laravel + PhpStorm

php - 使用 Laravel 4 遍历多个请求文件

php - PDO Mysql,想要更新甚至插入数据

java - 基于 GIS 的报告和维护工具

php - 有没有一种方法可以通过 PHP 删除注释而无需为其分配 ID?

php - Laravel `delete()` 影响其他时间戳列

angular - Angular 的 Laravel Rest API Google Auth

php - 拉维尔 4 : How to Change Laravel getQueryLog to complete SQL command

mysql - Laravel 模型 - 想要检查 DB::raw 中的 where (or) orWhere

php - 使用 Codeception 和 Laravel 进行登录测试