add user_id property on notification

This commit is contained in:
2026-03-12 09:39:36 +01:00
parent 2dcc861317
commit a65dcdee3b
+5 -5
View File
@@ -3,7 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\UserCreated; use App\Events\UserCreated;
use App\Mail\TestMail; use App\Events\UserValidated;
use App\Mail\ValidateMail; use App\Mail\ValidateMail;
use App\Models\Notification; use App\Models\Notification;
use App\Models\User; use App\Models\User;
@@ -50,6 +50,7 @@ class UserController extends Controller
$notification = Notification::create([ $notification = Notification::create([
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}", 'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}",
'user_id' => $user->id,
]); ]);
$admins = User::whereIn('role', [1, 2])->get(); $admins = User::whereIn('role', [1, 2])->get();
$notification->users()->attach( $notification->users()->attach(
@@ -182,11 +183,9 @@ class UserController extends Controller
try { try {
$user = User::find($id); $user = User::find($id);
$content = "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"; $notifications = Notification::where('user_id', $user->id)->get();
//$notification = Notification::where('user_id', $user->id)
$notification = Notification::where('content', $content)->first();
if ($notification) { foreach ($notifications as $notification) {
$notification->users()->detach(); $notification->users()->detach();
$notification->delete(); $notification->delete();
} }
@@ -202,6 +201,7 @@ class UserController extends Controller
'lastname' => $user->lastname, 'lastname' => $user->lastname,
]; ];
Mail::to($user->email)->send(new ValidateMail($data)); Mail::to($user->email)->send(new ValidateMail($data));
broadcast(new UserValidated($user));
return response()->json(['message' => 'User validated successfully']); return response()->json(['message' => 'User validated successfully']);