Laravel Eloquent parent with multiple polymorphic children
I’ve been trying to model a relationship in Laravel between a ShapeContainer
entity and different shapes with unique properties, but a common Shape
interface (with getArea
and getPerimeter
methods). I’ve read up on the examples in the laravel documentation (posts
, videos
, comments
), but in that example the child entity (Comment
) can belong to different types of parents. In my case I want the parent entity (ShapeContainer
) to be able to handle different types of children (Circle,
Rectangle
etc).