engagement system

This commit is contained in:
2026-02-06 15:13:20 +02:00
parent 2e1ce0d93b
commit 7a99c3eb59
15 changed files with 1079 additions and 2 deletions
@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers;
use App\Models\Bookmark;
use App\Models\Product;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class BookmarkController extends Controller
{
/**
* 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,
]);
}
}