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

安稳与你 提交于 2020-01-03 16:56:16

问题


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


A simple use CRUD app as following,

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()


Could someone give me an hint?.


回答1:


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

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.



来源:https://stackoverflow.com/questions/24605170/laravel-4-call-to-undefined-method-illuminate-database-eloquent-collectionlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!