4
I created a relationship between my tables using ManyToMany and currently I need to return a Json with the information, but my tables meet this way;
// 1. Produtos
+-------------+
| id |
| name |
| description |
| image |
|_____________|
// 2. Variações
+-------------+
| id |
| SKU |
|_____________|
// 3. Produtos_variacoes
+-------------+
| prod_id |
| variation_id|
|_____________|
1 - The table Produtos stores general product information.
2 - The table Variações stores the codes that the product has
3 - The table produtos_variações serves as a "pivot" for storing id of the product and the id of variation.
When I return a Json between 2 tables I do it this way;
$dados = Product::with('Variacoes')->get();
return Response::json($dados);
But I need to relate the table produtos_variações to be able to know which product has which variation.
How can I do that?
How JSON is being returned today?
– Rodrigo Rigotti
if I use the example I showed in the post this returning a list of products with a list of variations, however these tables have no relationship between themselves.
– RFL
This is returned in the field
pivotof your json– Wallace Maxters
Your question is not very clear. Why you need to relate
produtos_variacoes? Isn’t it already related? You have set up yourbelongsToMany?– Wallace Maxters