add readNotifications route and bruno's request

This commit is contained in:
2026-01-08 14:04:53 +01:00
parent 2790026475
commit 51791a3b34
4 changed files with 33 additions and 1 deletions
@@ -38,4 +38,18 @@ class NotificationsController extends Controller
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
}
}
public function readNotifications(Request $request): JsonResponse {
try {
$user = $request->user();
$notificationIds = $user->notifications()->pluck('notification_id');
$user->notifications()->updateExistingPivot($notificationIds, ['unread' => 0]);
return response()->json(['message' => "Notifications marquées comme lues"], 200);
} catch(\Exception $e) {
Log::info($e->getMessage());
return response()->json(['message' => "Server error"], 500);
}
}
}