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 Table 2: galleries Table 3: Gallery categories 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 thanks already! You need it to work for your schema: To follow this corrective conventions, you will need: 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:
cat_id
cat_name
gallery_id
Gallery_name
cat_id
gallery_id
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
// 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
// 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'); }
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
Post a Comment