Support the ongoing development of Laravel.io →
Eloquent Architecture
Last updated 2 years ago.
0

Have a look at Polymorphic Relations in the documentation, that fits perfectly to your case!

Last updated 2 years ago.
0

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? ;)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

TorchSK torchsk Joined 17 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.