Thursday, 5 September 2013

Explain Laravel Polymorphic Relations

Explain Laravel Polymorphic Relations

http://laravel.com/docs/eloquent#polymorphic-relations
Polymorphic relations allow a model to belong to more than one other
model, on a single association. For example, you might have a photo model
that belongs to either a staff model or an order model.
I don't really understand this use case. Does this mean that a member of
staff could own a photo, or the photo could be placed in an order? Why not
just put photo_id in staff table and photo_id in order table?
Could somebody please provide an alternative, simple to understand,
example where polymorphic relations may be used?

No comments:

Post a Comment