How do we paginate records for belongsToMany relationship ?
i was watching laracasts lesson:
Laravel From Scratch: Part 31 - Sorting Posts By Tags
url : https://youtu.be/Lq9rOAYW-S0
but there is not part talking about pagination for relational records : (
my code is as below:
public function index(Category $category)
{
$posts = $category->posts;
dd($posts);
return view('pages.frontend.categories.index', compact('posts'));
}
i get around 50 records for the current category i am checking post for. I want to have a limit of 20 record per page.
if i do :
$posts = $category->posts->paginate(20);
i get error:
BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::paginate does not exist.