Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicates #2

Open
haleyngonadi opened this issue Aug 13, 2018 · 4 comments
Open

Duplicates #2

haleyngonadi opened this issue Aug 13, 2018 · 4 comments

Comments

@haleyngonadi
Copy link

Thank you for this! I'm having an issue where when a user reacts to a post, if they react again, instead of replacing the current reaction, a new record is created, with the exact same reaction!

Any way to fix this?

@nguyentranchung
Copy link

$reactable->reactions()->attach(

using sync() methood instead of attach()

@digitalcoaster
Copy link

digitalcoaster commented Oct 18, 2018

this does not fix the issue

@haleyngonadi
Copy link
Author

haleyngonadi commented Oct 18, 2018

this does not fix the issue

Hey, maybe my solution will help you:

    $userId =   auth()->user()->id;
    $reaction = Reaction::findOrFail($request->react_id);
    $post = Post::where('id', $request->post_id)->first();

  if($post->reactions) {
    $check = $this->reactValidate($post->id, $userId);
    $alreadyReacted = $check[0]->count;
    $reactableID = $check[0]->rid;

    if ($alreadyReacted >= 1) {
              DB::table('reactables')->where('id', $reactableID)->delete();

    }

      auth()->user()->reactTo($post, $reaction);

The other bit:

   private function reactValidate($postid, $userID) {
      return DB::select('select r.id as rid, count(r.reaction_id) as count from reactables r
      where r.reactable_id ='. $postid .' and r.responder_id ='. $userID);
    }

@digitalcoaster
Copy link

this does not fix the issue

Hey, maybe my solution will help you:

    $userId =   auth()->user()->id;
    $reaction = Reaction::findOrFail($request->react_id);
    $post = Post::where('id', $request->post_id)->first();

  if($post->reactions) {
    $check = $this->reactValidate($post->id, $userId);
    $alreadyReacted = $check[0]->count;
    $reactableID = $check[0]->rid;

    if ($alreadyReacted >= 1) {
              DB::table('reactables')->where('id', $reactableID)->delete();

    }

      auth()->user()->reactTo($post, $reaction);

thank you for your answer, but it says that the react validate method does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants