mysql - Eloquent Pivot Relationship with 2 tables -


I can not be that it is not sure, but I have two tables:

 < code> parts: ID part_number details multiplier Kit type ======================================== = ====================================== 2012 ADH01-PRCD01-E program disks 1.00 0 3 2013 ADH01-STHO01 e aim Worksheet 1.00 0 3 2014 ADH01-STPT01 e student post-test VA 1.00 0 3 2015 ADH01-STPT02 e student post-test vB 1.00 0 3 kit_parts: ID kit_id part_id ======= == ===================== 1 2012 2013 2 2012 2014 3 2012 2015  

If parts have been set in the table , Then he Need to see the parts of the kit to know what is included.

I am trying to figure out how this can make a relationship with Laravel in a relationship with a model.

Does anyone know that this is possible?

Thank you

Assuming that each part only ever a kit, You can do this in your part model with a one-to-many relationship referenced column at kit Public Function Kit () {Return $ This- & gt; Hamind ('part', 'kit', 'kit'); }

For any individual part (say, part # 2012), you can get all the parts in its kit in such a way as:

 < Code> $ kitParts = Part:: Search (2012) - & gt; Kit;  

If you need to recover the associated parts as part of the query for many parts, you avoid the kit query for each part in the relationship. To make the relationship curious can be set:

 with  $ parts = part :: (- 'kit') - & gt; get ();  

... then there is now a kit attribute in each element of the result $ parts that you can access: kit as kit) p>

  foreach (part $ as part $) // Parts kit in}}  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -