php - Laravel many to many relashionship -
i have users
, meetings
, comments
tables , want users able post comments on users profile , meetings.
i know how make 1 many relationships users , comments tables, want comments saved in 1 table , show comments on users profile , meetings.
this table structure:
users id name comment_id meetings id name comments id user_id comment
tl;dr solution use polymorphic relationships laravel makes easy.
imho don't think many-to-many relationship job. mean that:
- a user can post multiple comments. okay
- a comment can belong multiple user. weird
- a meeting can have multiple comments. okay
- a comment can belong multiple meetings. weird
plus need 2 comments
tables achieve that. instance comment_user
table , comment_meeting
.
the kind of relationship fit situation polymorphic one. name can scary because comes ancient greek. concept behind name simple. , laravel makes polymorphic relationships easy. recognize situation in example given in laravel documentation ;)
Comments
Post a Comment