A
A
AlpineMilk2018-07-29 10:15:04
HTML
AlpineMilk, 2018-07-29 10:15:04

"Like" button without authorization?

Hello! There is a task to make a "Like" button under the record, without authorization. I am doing with ajax.
When you click on the "I like" button, the user is given a cookie, and I check that if this cookie exists, then I add a class to the template (the class changes the color of the icon to red), and when clicked again, the counter decreases. The problem is that if you like 1 post, this cookie is created and a class is added (everything is ok, it should be), but when you go to another article, it is already marked as liked (that is, the class is specified, and the icon is highlighted in red), and if you click on the button, the counter will change to - 1
in the template looks like this

class = "@if(Cookie::get('like')) like-active @endif"

How can I change this check so that other articles are not highlighted as active?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2018-07-29
@trofimovdev

Add a unique record ID to each cookie, e.g. And check, respectively, also with him.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question