amitsolanki24_'s avatar

Laravel Relationship

Can anyone please tell me difference between morphMany vs morphTo and morhMany vs hasMany and morphMany vs belongsToMany

And when should I use these?

And what is concept of pivot table?

0 likes
4 replies
amitsolanki24_'s avatar

@tykus No, I just want to know when should I use which relationship.

And I have a doubt why we use morph many relationship instead of hasmany. We can do same thing with hasmany relationship.

tykus's avatar

@amitsolanki24_ as @jaseofspades88 mentioned, review the docs - a morphMany is not the same as a hasMany

A polymorphic relationship allows the child model to belong to more than one type of model using a single association. For example, imagine you are building an application that allows users to share blog posts and videos. In such an application, a Comment model might belong to both the Post and Video models.

Please or to participate in this conversation.