Answer the question
In order to leave comments, you need to log in
How to merge 2 collections in Eloquent?
I have 2 tables - t-shirts and color. Many-to-many ratio.
I get the collection of t-shirts in the controller $products = Product::all();
AND I display the t-shirts in Twig
{% for Product in Products %}
{{ Product.name }}
{% endfor %}
But now how to display the colors? Getting T-shirt colors using a many-to-many relationship $colors = Product::all()->colors;
Question. As a result, I have two objects - t-shirts and colors. Now, in theory, they should be combined by keys. I have a feeling that I am doing something wrong, this can be done more correctly. I will be grateful for advice.
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