So I'm a bit lost at this part. On my site I would like the give the ability for users to like profile pages.
So my logic is this.
I have a database table named user_likes
, this contains 3 rows, id, user_id, liked_by
.
The actual profile page has a like button on it with a class like.
When the user clicks on it in inserts the data in to the user likes table
and changes the button text to unlike and the class to unlike too with ajax.
And this is the part where I'm stuck.
So the profile has a has many relation likes
, I can count the likes received, but I'm stuck at that part how to keep the button unliked after page refresh.
Because my logic was this (but its a fail): onclick the button, data insert with ajax, button change with ajax, grab the liked by id and if that equals to the logged in users id keep the button unliked.
But since it returns a list of array I can't do that.
So I don't want anybody to code it for me, I would just like a hint for this if its not a big request.