Laravel 4 Binding paginated
I am trying to display a list of products with matching categories using the following in my controller:
return View::make('products.index')
->with('categories', Categories::with('products')->orderBy('name', 'asc')->Paginate(15))
But pagination doesn't work, it displays all products (500+), while I only want to show 15 on each page. Here are my models:
Categories:
public function products()
{
return $this->belongsToMany('Products');
}
Products:
public function categories()
{
return $this->belongsToMany('Categories');
}
How can I make pagination work?
+3
source to share