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;
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']);