As an example, suppose I sell air conditioners and air filters. They are all products in my product table. But I also have a related_products table for which filters go with each air conditioner where product_id is the AC and filter_id is the corresponding product_id in the product table for the filters:
product_id | filter_id |
---|---|
1 | 10 |
1 | 11 |
2 | 10 |
2 | 15 |
How are these relations defined in Laravel Eloquent? This seems almost like a pivot table referring to a single products table. The related_products table doesn't have an associated Model (I don't think) so would I try to define this relationship all in the Product model?
source https://stackoverflow.com/questions/77455282/eloquent-relationship-for-related-products
No comments:
Post a Comment