Chase
Chase

Reputation: 151

Laravel 4 Paginate and OrderBy issue

I am trying to paginate with an orderBy tag and I am having issues with it. Here is my code:

$posts = Post::where('draft', '=', 0)->orderBy('created_at', 'id')->paginate(1)->get();
    return View::make('home')->with('posts', $posts);

But it returns with:

Missing argument 1 for Illuminate\Support\Collection::get()

Can someone help me with my errors. Thanks

Upvotes: 1

Views: 955

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219938

Just drop the call to get(). The paginate method itself already does the database query:

$posts = Post::where('draft', '=', 0)->orderBy('created_at', 'id')->paginate(1);

return View::make('home')->with('posts', $posts);

Upvotes: 2

Related Questions