Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?.

like image 636
user2837851 Avatar asked Jan 28 '26 17:01

user2837851


1 Answers

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.

like image 136
Unnawut Avatar answered Jan 30 '26 12:01

Unnawut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!