I created a relationship between my tables using ManyToMany
and I currently need to return a Json with the information, but my tables are found like this;
// 1. Produtos
+-------------+
| id |
| name |
| description |
| image |
|_____________|
// 2. Variações
+-------------+
| id |
| SKU |
|_____________|
// 3. Produtos_variacoes
+-------------+
| prod_id |
| variation_id|
|_____________|
1 - The Produtos
table stores general product information.
2 - The Variações
table stores the codes that the product has
3 - The produtos_variações
table serves as the "pivot" to store the id
of the product and id
of the variation.
When I return a Json between 2 tables I do the following way;
$dados = Product::with('Variacoes')->get();
return Response::json($dados);
But I need to relate the produtos_variações
table to know which product has what variation.
How can I do this?