Answer the question
In order to leave comments, you need to log in
How to link a model to itself in Eloquent?
Hello.
I decided to implement the "Similar Products" functionality in a self-written store.
We will put products in the admin panel for each product.
All this is written in a table.
product_related
product_id | product_related_id
product_related
product_id | product_related_id
1 2
product_related
product_id | product_related_id
2 1
Answer the question
In order to leave comments, you need to log in
It depends on how you are going to interpret such records.
For example, if product A page displays product B as related, this does not necessarily mean that product A should be displayed as related on product B page.
Otherwise, the presence of a duplicate relationship must be controlled at the application level by making a verification request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question