B
B
bwylla2020-10-13 22:44:01
Laravel
bwylla, 2020-10-13 22:44:01

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');
    }


And how can pagination be applied? After all, in the controller you can’t just enter Category::find(2)->paginate(15) because we get only 1 category

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question