Models: User, Thread, Post, Revision
User hasMany Thread
Thread belongsTo User
Thread hasMany Post
Post belongsTo Thread
Post hasMany Revision
Revision belongsTo Post
Table Design (example)
Thread: id,title,user_id,timestamps()
Post: id,thread_id,user_id,text,timestamps() (no need for a boolean as we only want to check if they edit, not initial post)
Revision: id,post_id,text,approved(boolean, default false),timestamps()
Then when displaying the thread you will loop over posts to display (or extract logic to repo), in that loop you can check $post->revision->count() and if it is greater than 0 check if any of the revision have their column approved set to true, then grab the latest() one with approved column set to true. That is what I would do.
This is a raw example
// mysite.com/thread/{id}
// $posts = Thread->posts->oldest() // you will want to show oldest first, like any site forum
foreach($posts as $post)
{
if($post->revision->where('approved',true)->count() > 0) // show latest approved post content
{
$updated = $post->revision->where('approved',true)->latest()->first(); //sort by a timestamp column desc (latest) and just grab the first approved one
// display post
$updated->text
} else {
// there are no revisions, or no approved revisions so display original post content
$post->text
}
}
This is just a general example. It may or may not be ideal code design. Just showing a general idea on how I would go about it. You could then have a ticker with $count = Revision::where('approved',false)->count() that shows if there are any posts that have been edited that you need to approve. If you approve it, change approved to true, if not, delete post all together.
If you do not want to delete the revision even if you deny it then add a seen boolean column to revision table and mark that as true and change the counter logic to this $count = Revision::where(['approved' => false, 'seen' => false])->count()
That way, if you seen it, and deny it, the approved column stays false, and seen counter updates to true and you are no longer notified about it.
@nathanrobjohn