问题
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