change notifications functions

This commit is contained in:
2025-12-17 17:18:37 +01:00
parent 08c51473a7
commit 08459ac627
5 changed files with 10 additions and 63 deletions
@@ -10,24 +10,10 @@ use Illuminate\Support\Facades\Log;
class NotificationsController extends Controller
{
public function createNotification(Request $request, int $id): JsonResponse {
$notification = Notification::create([
"content" => $request["content"]
]);
$notification->users()->attach($id);
return response()->json(['message' => 'Notification created successfully']);
}
public function getNotifications(Request $request, int $id): JsonResponse {
public function getNotifications(Request $request): JsonResponse {
try {
$user = User::findOrFail($id);
return response()->json([
'data' => $user->notifications
'data' => $request->user()->notifications
]);
} catch(\Exception $e) {
Log::info($e->getMessage());
@@ -37,10 +23,9 @@ class NotificationsController extends Controller
public function deleteNotification(int $userId, int $notificationId): JsonResponse {
public function deleteNotification(Request $request, int $notificationId): JsonResponse {
try {
$user = User::findOrFail($userId);
$user->notifications()->detach($notificationId);
$request->user()->notifications()->detach($notificationId);
$notification = Notification::find($notificationId);
if ($notification && $notification->users()->count() === 0) {
@@ -53,5 +38,4 @@ class NotificationsController extends Controller
return response()->json(['message' => 'Erreur lors de la suppression'], 500);
}
}
}