Distant relationship with Laravel 5.5

Asked

Viewed 60 times

0

Guys, I need some urgent help!

I have the following situation:

Tables:

saidas
   id
   ...

saidas_produto
   id_saida
   id_entrada_produto

entradas_produtos
   id
   id_entrada
   id_produto
   ...

entradas
  id
  ...

My Warehouse system, works with input and output of various products. Where an output is made on an item that has been added on the input (in_products) -> here is where the input items(products) are stored. In other words, an output is not directly related to a product but with a product that has been input.

I was able to make the relationship right in relation to the input:

public function produtos() {
    return $this->belongsToMany('Estoque\Produto', 'entradas_produtos', 'id_entrada', 'id_produto')->withPivot('id', 'numero_lote', 'vencimento_lote', 'quantidade', 'valor_unitario')->orderBy('entradas_produtos.id', 'asc');
}

How do I make this relationship, going through the table saidas_products, picking my product that is inside entradas_products and taking the name of the product that is inside products?

I’ve tried everything and nothing :(

  • @Juniornunes there is that ta: if in my table saida_products had direct relationship with products, the same input has would make it good. But the output has a particularity. Note that in the table I have the id_entrada_product. Thus, my way of output is not in a direct product but in an item that was given at the entrance.

  • @Juniornunes sorry for ignorance, rsrsrs. Could you write me how you’re thinking about this relationship?

  • Input and Output are separate modules, say. A system user first registers N products, and then he will register an entry. An entry can contain N products. After that, the entrance died. The exit serves to control the stock, in the Storeroom is done this way. Where the output is done in an input item (in_products) > where the product id is stored here. Which serves only as a reference. I didn’t quite understand the question, but I believe I don’t need to get an entry through an exit.

  • For the tables in_products and saidas_products I do not have Model, for me they are auxiliary tables.

  • Ask me in your question the database model with the relations (table diagram and relation)!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.