0

I have four tables

quotation

  • id

item

  • id
  • quotation_id

article

  • article_id
  • quotation_id

articleItem

  • pivot_item_id
  • pivot_article_id

either articleItem have more columns

and i need right syntax of manyToMany relation between item and article

at the moment i have in item model

return $this->belongsToMany(Article::class,'articleItem','pivot_item_id','pivot_article_id','id','article_id');

i really dont know where to put quotation_id in this relation... is it possible?

2 Answers2

1

How is item related to article? Is an article assigned to an item or vice versa? More information would be helpful. Maybe give an example of what you are trying to achieve.

Many-to-many relationship is usually 3 tables such as users, roles, role_users. What you have looks similar to a polymorphic many-to-many with item and article sharing a relationship with quotation.

  • item is set of articles able to add to quotation... different items can hold different articles and they can repeat in items... quotation can have many items and much more articles. – Petr Kamen Spinar Mar 17 '21 at 21:57
  • at the moment with relation above when i call item->articles i have returned all articles but for all quotations. pivot table have info about quantity and price of article in item but it can be different for different items and for the end i want to have just one entry of article for each kind... i need to do relations from each corner to each corner... – Petr Kamen Spinar Mar 17 '21 at 22:04
  • for more either name of tables and columns are not so easy... so i need to specify them – Petr Kamen Spinar Mar 17 '21 at 22:08
  • and one think... article can be added to quotation without being in item... :D – Petr Kamen Spinar Mar 17 '21 at 22:11
  • thank you, you pushed me the right way ;) – Petr Kamen Spinar Mar 17 '21 at 22:25
0

solved by adding

->whereHas('quotation', function ($query) {$query->where('id', $this->quotation_id);})

at the end of declaration of relation.