php - Many to Many relationships with Laravel / Eloqeunt -


I think I understand the best for the sake of the part, but I still have some difficulties understanding the many relationships .

I am preparing a sample database, and hopefully you guys can help me understand it correctly.

Table 1: Categories

  • cat_id
  • cat_name

    Table 2: galleries

    • gallery_id
    • Gallery_name

      Table 3: Gallery categories

      • cat_id
      • gallery_id

        So how would I go about my model? I found this topic, but it did not look right. Maybe because I have a little more complicated relationship with this requirement. I think the argument confuses me because I expected that there will be rules for the products, while it would be an example of the words that are being produced.

        If you can explain this with your sample, then it will give me the related values ​​() and hasMany () the methods and their parameters better Help in understanding the way. I am also confused with some examples that do not take any foreign key parameters

        thanks already!

        You need it to work for your schema:

          // Category Model $ primaryKey = 'cat_id' protected; Public celebration galleries () {return $ this- & gt; Related Tomen ('Gallery', 'Gallery categories', 'Gallery_ID', 'Cat_ID'); } // gallery model protected $ primaryKey = 'gallery_id'; Public Function Categories () {Return $ this- & gt; Affiliateomany ('category', 'gallery categories', 'cat_id', 'gallery_id'); } // then: $ range = category :: first (); $ Range & gt; Galleries; // Gallery Model Collection   

        To follow this corrective conventions, you will need:

          // Categories of tables : Id,. .. galleries: id, ... category_gatery: id, category_id, gallery_id [, timestamp] // model // category gallery of public celebrations () {return $ this-> Affiliation (gallery); } // Gallery Public Tasks Categories () {Return $ this- & gt; Affiliation Value ('Category'); }   

        If you want to make most of the structure then the second solution is as good, but if you want to rely on your schema, you can adjust it to a well-known.

        Note: Hamani is 1-m relation, isTo is equivalent to it, whereas pivot tables with many-to-many relationships For, you relatedness at both ends

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -