S
S
smilelan2020-04-16 00:08:54
Laravel
smilelan, 2020-04-16 00:08:54

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

2 answer(s)
N
NeuroPastor, 2020-04-16
@NeuroPastor

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.

J
jazzus, 2020-04-16
@jazzus

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 question

Ask a Question

731 491 924 answers to any question