From 863abeeeaf77ca2e2ab96837dbf3768fa02b8ecc Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Mon, 14 Mar 2022 16:20:09 -0400 Subject: [PATCH] Fix favouriting --- paste.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/paste.php b/paste.php index d904732..feda672 100644 --- a/paste.php +++ b/paste.php @@ -83,7 +83,7 @@ $p_visible = $paste->visible; $p_expiry = $paste->expiry; $p_password = $paste->password; $p_encrypt = (bool) $paste->encrypt; -$paste_is_favourited = $current_user !== null && $current_user->favourites->where('paste_id', $paste->id)->count() === 1; +$paste_is_favourited = $current_user !== null && $current_user->favourites->where('id', $paste->id)->count() === 1; $is_private = $p_visible === '2'; @@ -140,10 +140,12 @@ if (!empty($p_expiry) && $p_expiry !== 'SELF') { /* handle favouriting */ if (isset($_POST['fave'])) { if ($paste_is_favourited) { - $current_user->favourites()->detach($paste->id); + $current_user->favourites()->detach($paste); } else { - $current_user->favourites()->attach($paste->id); + $current_user->favourites()->attach($paste); } + + $paste_is_favourited = !$paste_is_favourited; } if ($p_encrypt == 1) {