Reputation: 5451
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());
}
Upvotes: 0
Views: 469
Reputation: 1084
I do recommend to create a model for that Stories table. Once done, you could do something like:
Story::orderby('story_name', 'ASC')->paginate(10);
Upvotes: 1
Reputation: 4878
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
.
Upvotes: 1