Have a look at Polymorphic Relations in the documentation, that fits perfectly to your case!
Thanks bastientanesie for response,
I knew about polymorphic relations, but I never actually give it a proper look. Unfortunately, I have my DB already set-up, and I am using multiple tables for comments according which model it belong to (eg. PhotoComment, UserComment, PostComment...)
Do you think it is better to have single table for this purpose?
Also, my main concern is. Should I create a service class for creating a comment with all validations and inject it in other classes that will use it, or should I just create methods for inserting comment in each service class separately (I have PostService class, PhotoService class etc...) .
Or... create a CommentService class, and child PhotoCommentService class, PostCommentService class, ... that will extend the base CommentService class? ;)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community