0
My doubt would be how to display table data in a relationship Many to Many with more than two related tables:
Ex: Main table SALE PIVO VENDA_DETALHE table (where to buy/idproduct/idcentrocust) PRODUCT TABLE Table CENTROCUSTO
MODEL SALE
public function produto()
{
return $this->belongsToMany(Produto::class,'venda_produto_centrocusto');
}
public function centrocusto()
{
return $this->belongsToMany(CentroCusto::class,'venda_produto_centrocusto');
}
PRODUCT MODEL
public function venda()
{
return $this->belongsToMany(Venda::class,'venda_produto_centrocusto');
}
MODEL COST CENTER
public function venda()
{
return $this->belongsToMany(Venda::class,'venda_produto_centrocusto');
}
CONTROLLER public Function create() { $sales= Sale::with('product','centrocusto')->get();
return view('venda.pedido.create',compact('vendas'));
}
IN VIEW
foreach ($vendas as $venda) {
foreach ($produtos as produto) {
foreach ($produtos as produto) {
// Aqui quero rodar os produtos e o centro de custo dessa venda;
Esta dando erro aqui, ela esta trazendo todos os centros de custos
}
}
}
He even took a look at the session Retrieving Intermediate Table Columns of documentation ?
– fernandosavio
I am reading, but I still could not implement, this giving error.
– frodrigues
Then you could put the part of the code that is giving error in your question (only the part with error, the whole code does not. Please :D ). And try to explain what you have already tried and what error is showing. So there will be more people to help you.
– fernandosavio
To edit the question just click the edit button (it is only for you not to post your questions here in the comment)
– fernandosavio