像一篇文章/评论只是一次,laravel

Information: I have 2 tables(users for the users of the website and new_themes for themes/posts(whatever) created by the users.

!!!There is no relationship between these 2 tables.(A user can create a new post if he is logged in)

Tables:

Users:
1   id 
2   name    
3   email   
4   password

New_themes:
1   id
2   title
3   text
4   upVotes
5   downVotes
6   TagName 

What I want to do:

I created the feature that user can like the post(but he can like it unlimited number of times) but I want them to be able to like just once in a life time a post.

What I can't figure out is the idea/structure/logic of how to make it. I am thinking of creating a table . A "pivot" one for tables users and new_themes(many to many relationship in Laravel)

1 id_user
2 id_theme

Where the both of them have a composite primary key so they won't be any duplicate values, so if the user wants to vote once again the same post he won't because there can't be duplicate values.

Here is the problem:

If this is the solution, I have doubt and no idea on how to populate the pivot table when a user likes a theme. If this isn't the solution any advice or idea will be very helpful for me to finish my last feature of my wep app.

Thank you very much.

What I can't figure out is the idea/structure/logic of how to make it. I am thinking of creating a table . A "pivot" one for tables users and new_themes(many to many relationship in Laravel)

That's the way to go. So it would look like this:

+---------+----------+
| user_id | theme_id |
+---------+----------+
| 1       |        1 |
+---------+----------+
| 12      |        1 |
+---------+----------+
| 14354   |        1 |
+---------+----------+

To 'like' a theme, just insert the user and theme id into the table. The rest is just taking care of the response from the database - giving the user feedback for his try to like something more than once etc.

And of course you should not forget the ability to unlike - so you need to delete from the table again... if you want users to unlike.

First you have to create a new table with following fields (id, user_id, theme_id, status) as you said, maintain the relation between user and theme in that table. when user like the theme insert a record with status 1 , if user unlike the theme, first check the user_id in the table, if user id is present then just update the status to 0 otherwise insert new entry with status 1.