use UserRegistered notification
This commit is contained in:
@@ -2,16 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\UserCreated;
|
||||
use App\Events\VolunteerRoleUpdated;
|
||||
use App\Mail\CreateUserByAdminMail;
|
||||
use App\Mail\DeactivateAccountMail;
|
||||
use App\Mail\DeleteAccountMail;
|
||||
use App\Mail\RegisterMail;
|
||||
use App\Mail\UpdateRoleMail;
|
||||
use App\Mail\ValidateMail;
|
||||
use App\Models\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\UserRegistered;
|
||||
use App\Services\GetRole;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -55,30 +54,8 @@ class UserController extends Controller
|
||||
"email_notifications" => 1,
|
||||
]);
|
||||
|
||||
$notification = Notification::create([
|
||||
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"
|
||||
]);
|
||||
$admins = User::whereIn('role', [1, 2])->get();
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
Notification::sendNow($admins, new UserRegistered($user));
|
||||
|
||||
return response()->json(['message' => 'User created successfully']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user