bookmarks() ->with(['product.category', 'product.user']) ->whereHas('product', function ($query) { $query->approved(); }) ->latest() ->paginate(12); return view('bookmarks.index', compact('bookmarks')); } /** * Toggle bookmark for a product. */ public function store(Product $product): JsonResponse { $user = Auth::user(); // Check if user already bookmarked $existingBookmark = Bookmark::where('user_id', $user->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, ]); } }