Member-only story
Do you know what is polymorphic in Laravel?
A polymorphic is a relationship allow us to cross with more type of Model.

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. Or Tag
model might also belong to Post
and Video
models.
Here I gonna show you 3 type of polymorphic which is :
- One to One
- One to Many
- Many to Many
One To One (Polymorphic)
A one-to-one polymorphic relation is similar to a typical one-to-one relation; however, the child model can belong to more than one type of model using a single association. For example, a blog Post
and a Comment
may share a polymorphic relation to an Image
model.
posts id - integer name - stringcomments id - integer name - stringimages id - integer url - string imageable_id - integer imageable_type - string // this will below to…