CyberDays
CyberDays

Reputation: 1

Laravel Method paginate does not exist trying controller

$article = Article::all()->sortBy("order")->paginate(3);

return view('nieuws' , compact('article'));

wont work this is the error I get back: Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

Upvotes: 0

Views: 243

Answers (1)

STA
STA

Reputation: 34668

When you're using all() you get all the rows from the table and get a collection. You can only invoke "paginate" on a Query, not on a Collection. :

$article = Article::orderBy("order")->paginate(3);

There is no sortBy() method on the query builder, it should be orderBy. You can only invoke "sortBy" on a Collection, not on a Query.

Upvotes: 2

Related Questions