dimanche 24 juin 2018

In need of a logic to create comments in laravel

Ok so the basis is that I want to be able to have comments on each of my post. The comments will have a reply button for each. It’s not multi threaded so one comment will have many replies. Those replies won’t have replies. Also I want to be able to like and dislike a comment/reply. All of this will not be bind to the user model or any of such. The public visitors will be able to add comments and reply to comments but the approval is needed.

So here is the logic I got so far. Am I on the right track here (hoping this post may help someone else as well):

So i create aComment model. And then create a table named comments. And I create a model named Reply and a table named replies And finally, a model name Like and it’s table likes

So the relationship is: comments will have many replies and replies belongs to one comment replies & comments will have many likes.

And now for the logic:

I will use AJAX to call the store function on the CommentController to store comments. And I will call the store function on the ReplyController to store the replies. As for the likes, LikeController store function will store the likes for the comment and reply.

Here is the table structure:

  1. Comments table

    • id
    • post_id
    • name
    • email
    • comment
    • approved
    • timestap
  2. Replies table

    • id
    • comment_id
    • name
    • email
    • comment (or reply)
    • approved
    • timestamp
  3. Likes table

    • id
    • comment_id
    • reply_id
    • like
    • dislike
    • timestamp

Now what I do not understand is, likes table. Is it right to have comment_id and reply_id and also like and dislike? I could call the store function everytime someone clicks the like or dislike and have it stored in the table and update the column if it is a reply or a comment by it’s id to the respective id columns. Is the logic right?

Also, if you guys have any suggestions or better and efficient way of doing this, please let me know. This is getting too long so I’ll just leave it here.

Edit

Also forgot to mention that I am not sure how I will be taking the amount of likes from db to blade and count it. Not with the current structure mentioned above.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2K4dNWn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire