Answer the question
In order to leave comments, you need to log in
How to implement voting in laravel?
Good night everybody! There was a need to create a vote FOR and AGAINST on the posts, the user can vote only once, I think I can check whether he voted earlier through cookies, but I would like to know if there are ready-made solutions for such voting on LARAVEL, if not, how best to implement the structure, Maybe someone has already experienced this.
Answer the question
In order to leave comments, you need to log in
I would do this:
You cut a table with answers (one line one answer):
-id
-number of the post (for which they vote)
-answer for or against. I would do a boolean.
Saw in a one-to-many relationship model.
The rest I think is clear.
Voting, likes, comments are best done through polymorphic links , so as not to produce the same tables and code. Because today they vote for a post, tomorrow for a photo, they want to transfer it to polymorphic ones, because it is 100 times easier with them, but it will already be cumbersome to fix. I would immediately make polymorphic ones, remove them together with related checks and action methods into a trait, which can already be connected to posts, photo-videos and any other models.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question