id) ->where('product_id', $product->id) ->first(); if ($existingBookmark) { // Remove bookmark $existingBookmark->delete(); $bookmarked = false; } else { // Add bookmark Bookmark::create([ 'user_id' => $user->id, 'product_id' => $product->id, ]); $bookmarked = true; } return response()->json([ 'success' => true, 'bookmarked' => $bookmarked, ]); } }