Should i use belongsTo or hasOne in Laravel?

后端 未结 3 1428
深忆病人
深忆病人 2020-12-12 12:51

Consider two models A and B

A -> relatedTo B is a one to one relationship

What is the differ

3条回答
  •  被撕碎了的回忆
    2020-12-12 13:36

    Main difference is as below:

    belongsTo and belongsToMany - you're telling Laravel that this table holds the foreign key that connects it to the other table.

    hasOne and hasMany - you're telling Laravel that this table does not have the foreign key.

提交回复
热议问题