use UserRegistered notification

This commit is contained in:
2026-03-28 15:27:30 +01:00
parent faa642f5d9
commit 7e6052d879
+2 -25
View File
@@ -2,16 +2,15 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\UserCreated;
use App\Events\VolunteerRoleUpdated; use App\Events\VolunteerRoleUpdated;
use App\Mail\CreateUserByAdminMail; use App\Mail\CreateUserByAdminMail;
use App\Mail\DeactivateAccountMail; use App\Mail\DeactivateAccountMail;
use App\Mail\DeleteAccountMail; use App\Mail\DeleteAccountMail;
use App\Mail\RegisterMail;
use App\Mail\UpdateRoleMail; use App\Mail\UpdateRoleMail;
use App\Mail\ValidateMail; use App\Mail\ValidateMail;
use App\Models\Notification; use App\Models\Notification;
use App\Models\User; use App\Models\User;
use App\Notifications\UserRegistered;
use App\Services\GetRole; use App\Services\GetRole;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@@ -55,30 +54,8 @@ class UserController extends Controller
"email_notifications" => 1, "email_notifications" => 1,
]); ]);
$notification = Notification::create([
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"
]);
$admins = User::whereIn('role', [1, 2])->get(); $admins = User::whereIn('role', [1, 2])->get();
Notification::sendNow($admins, new UserRegistered($user));
$webAdmins = $admins->filter(fn($admin) => $admin->web_notifications);
$notification->users()->attach($webAdmins->pluck('id')->toArray());
broadcast(new UserCreated(
$user,
$notification->id,
));
foreach ($admins as $admin) {
if ($admin->email_notifications) {
$data = [
'adminName' => $admin->name,
'adminLastname' => $admin->lastname,
'userName' => $user->name,
'userLastname' => $user->lastname,
];
Mail::to($admin->email)->send(new RegisterMail($data));
}
}
return response()->json(['message' => 'User created successfully']); return response()->json(['message' => 'User created successfully']);
} }