1
I’m in my first Laravel Framework project and I’m having difficulty in relationship N:M, I have the database structure fornecedor->fornecedor_produto->produto**
have my models:
class Fornecedor extends Model{
public function produtos()
{
return $this->belongsToMany(Produto::class)
->using(FornecedorProduto::class);
}
}
class Produto extends Model{
public function fornecedores()
{
return $this->belongsToMany(Fornecedor::class)
->using(FornecedorProduto::class);
}
}
class FornecedorProduto extends Pivot {}
my difficulty is that my table Pivot(fornecedor_produto) has 32 fields beyond the produto_id and fornecedor_id;
When I use the $fornecedor->produtos()->first()->pivot, returns me only
#attributes: array:2 [
"fornecedor_id" => 1
"produto_id" => 1
]
Got a way to return mine 32 other fields without putting all fields in the withPivot([col1,col2,...,col32]) in relationships?
Possible duplicate of Relationship of Laravel Tables
– Lucas Antonio