Search code examples
phplaravellaravel-3

Paging in PHP Laravel


I am trying to make a paging in Laravel, but i keep getting errors.

I try put

->paginate(3) 

On the return, but i keep getting errors like Call to undefined method Laravel\Paginator::get() and Call to undefined method Laravel\Paginator::order_by()

public function get_index()
{
    $categories = Category::all();
    return View::make("stories.index")
        ->with("title","Sexnoveller")
        ->with("categories", $categories)
        ->with("stories", DB::table('stories')
        ->order_by('id', 'desc')->get());
}

Solution

  • To use pagination call paginate() instead of get(). In your case that would be:

    return View::make("stories.index")
           // ...
           ->with("stories", DB::table('stories')
           ->order_by('id', 'desc')->paginate(3));
    

    Then in the view just remember to iterate over $stories->results.