Answer the question
In order to leave comments, you need to log in
How can pagination be applied in this case?
Two tables products and categories are connected by the category_products intermediary
In the controller I get all the goods by category
In the Category and Product models everything is by default
$category = Category::find(2);
#Product
public function category() {
return $this->belongsToMany(Category::class, 'category_products', 'category_id', 'product_id');
}
#Category
public function products() {
return $this->belongsToMany(Product::class, 'category_products', 'product_id', 'category_id');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question