Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Corbin's avatar

Looking for some advice and best practice input on how I should structure a user reports system for a forum project

I'm creating a forum, designing a moderation reports system, and trying to decide whether I should create two tables, or one for my user 'reports'. A user can essentially report content and it ends up in a moderation cue.

I have two thing I want moderated: Posts, and Comments. I would like to be able to query them both in a moderation area. What I can't decide is whether I should create just one reports table:

reports

  • id (int)

  • user_id (int)

  • post_id (int)

  • comment_id (int)

  • report (text)

Or should I break up my tables and have a post_reports and a comment_reports table separately. I'm hesitant to create two different tables because they share much of the same data and it would be an extra table to query. On the other hand I don't like the idea of a foreign key table cell going empty.

Which is probably better practice: one table, or two?

I'm trying to think long term effects with thing like eloquent and all. I've actually come across this same problem of whether or not to just use one, or multiple tables in many projects, so advice with this could really help.

0 likes
1 reply
Jaytee's avatar
Jaytee
Best Answer
Level 39

You could use a polymorphic relationship which essentially stores the name of the model in the database (App\Comment or App\Post) and an id for that model.

That way, in the future, if you integrate something else (as a silly example: Article) then it will pretty much work out of the box.

I always find that separating tables to make things clearer is better, but in this case, a polymorphic relationship will suffice.

2 likes

Please or to participate in this conversation.