From a65dcdee3be4f5436927112948ba50075ed3874b Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Thu, 12 Mar 2026 09:39:36 +0100 Subject: [PATCH] add user_id property on notification --- app/Http/Controllers/UserController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 751c741..91bddfc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use App\Events\UserCreated; -use App\Mail\TestMail; +use App\Events\UserValidated; use App\Mail\ValidateMail; use App\Models\Notification; use App\Models\User; @@ -50,6 +50,7 @@ class UserController extends Controller $notification = Notification::create([ 'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}", + 'user_id' => $user->id, ]); $admins = User::whereIn('role', [1, 2])->get(); $notification->users()->attach( @@ -182,11 +183,9 @@ class UserController extends Controller try { $user = User::find($id); - $content = "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"; - //$notification = Notification::where('user_id', $user->id) - $notification = Notification::where('content', $content)->first(); + $notifications = Notification::where('user_id', $user->id)->get(); - if ($notification) { + foreach ($notifications as $notification) { $notification->users()->detach(); $notification->delete(); } @@ -202,6 +201,7 @@ class UserController extends Controller 'lastname' => $user->lastname, ]; Mail::to($user->email)->send(new ValidateMail($data)); + broadcast(new UserValidated($user)); return response()->json(['message' => 'User validated successfully']);