Something like this might be a handy addition the the eloquent docs (or possibly the migration ones) on the main laravel site :-)
Jun 18, 2016
8
Level 122
Remember which table gets foreign key in relationship
I put together a little crib list for the common relationships to help me remember which relationship goes with which foreign key requirement.
I hope this is accurate. Please send any amends
+---------------+-------------+--------------+-------------------------+
| | self | other model | pivot |
+===============+=============+==============+=========================+
| hasOne | no key | self_id | |
| belongsTo | other_id | no key | |
| hasMany | no key | self_id | |
| belongsToMany | no key | no key | keys for self and other |
+---------------+-------------+--------------+-------------------------+
self is the model you are writing the relationship in and other model is the one you want the relationship with.
Please or to participate in this conversation.