I have posts
, users
and favorites
table.
For example, I make some post favorited for a user with an id of 3 like this :
User::find(3)->favorites()->attach($post->id);
and if users send request twice it will insert this favorite with this post_id
, user_id
twice.
I want to check if a post is not liked by this user, then save record in the database.
or if a post is favorited then unfavorite it.
how can I do this with eloquent relationship ??
I have User
, Post
models.