create notification when register

This commit is contained in:
2025-12-15 16:45:51 +01:00
parent dfb70cc5ce
commit eab9565c7d
7 changed files with 1191 additions and 533 deletions
+11 -1
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Notification;
use App\Models\User; use App\Models\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -36,7 +37,7 @@ class UserController extends Controller
$phone = new PhoneNumber($request["phone"], 'FR'); $phone = new PhoneNumber($request["phone"], 'FR');
User::create([ $user = User::create([
"name" => $request["name"], "name" => $request["name"],
"email" => $request["email"], "email" => $request["email"],
"password" => Hash::make($request["password"]), "password" => Hash::make($request["password"]),
@@ -45,6 +46,15 @@ class UserController extends Controller
"phone" => $phone->formatInternational(), "phone" => $phone->formatInternational(),
]); ]);
$notification = Notification::create([
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}",
]);
$admins = User::whereIn('role', [1, 2])->get();
$notification->users()->attach(
$admins->pluck('id')->toArray()
);
return response()->json(['message' => 'User created successfully']); return response()->json(['message' => 'User created successfully']);
} }
+1 -1
View File
@@ -12,6 +12,6 @@ class Notification extends Model
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{ {
return $this->belongsToMany(User::class, 'user_notification', 'notification_id', 'user_id'); return $this->belongsToMany(User::class, 'notification_user', 'notification_id', 'user_id');
} }
} }
+1 -1
View File
@@ -57,6 +57,6 @@ class User extends Authenticatable
public function notifications(): \Illuminate\Database\Eloquent\Relations\BelongsToMany public function notifications(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{ {
return $this->belongsToMany(Notification::class, 'user_notification', 'user_id', 'notification_id'); return $this->belongsToMany(Notification::class, 'notification_user', 'user_id', 'notification_id');
} }
} }
Generated
+1174 -526
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="logoIcone.png" /> <link rel="icon" type="image/svg+xml" href="logoIcone.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Comité des fêtes de Beaupont</title> <title>Comité des fêtes de Beaupont</title>
<script type="module" crossorigin src="/assets/index-rvA2OT8-.js"></script> <script type="module" crossorigin src="/assets/index-DyR9y3T_.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-K0Ho3vqG.css"> <link rel="stylesheet" crossorigin href="/assets/index-DBz-GVvs.css">
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
+1 -1
View File
@@ -39,7 +39,7 @@ Route::middleware(['web', 'auth:sanctum'])->get('/users/tasks/{idTask}', [UserCo
Route::middleware(['web', 'auth:sanctum'])->get('/users/{id}/notifications', [NotificationsController::class, "getNotifications"])->whereNumber('id'); Route::middleware(['web', 'auth:sanctum'])->get('/users/{id}/notifications', [NotificationsController::class, "getNotifications"])->whereNumber('id');
Route::post("/users/{id}/create/notification", [NotificationsController::class, "create"])->whereNumber('id'); Route::middleware(['web', 'auth:sanctum'])->post("/users/{id}/create/notification", [NotificationsController::class, "create"])->whereNumber('id');
Route::middleware(['web', 'auth:sanctum'])->get('/users/search', [SearchController::class, "searchUsers"]); Route::middleware(['web', 'auth:sanctum'])->get('/users/search', [SearchController::class, "searchUsers"]);
+1 -1
View File
@@ -1,4 +1,4 @@
headers { headers {
Accept: application/json Accept: application/json
X-XSRF-TOKEN: X-XSRF-TOKEN: eyJpdiI6IjdETzVjT3JoTWU2VE5nMVBKNnBUUVE9PSIsInZhbHVlIjoiWjhvNTRqTzY2MEhxM01MK1lSOFB0NnBvRU4rL1U2OEg0RTdvbXc5ZVQvK0JJMFhWUDFWWS9iSEFsZzdtS3hYd1ZkY2tJcWNpMDNVMlVnVGFGdTJGQzhqSFdCc0V4RVlBUkdObkVhdVh4RisxMWEvcFh4NXZkQTZyL3kvbmJ6T0EiLCJtYWMiOiIyYzA2NjkxYjRhMWE5ZGE2ZjNhZGFjOGFkZDBjN2Y0NTBiMDhiMzAwOThlNWVhOWQzYzVmNzU1NzczNWZjMWIzIiwidGFnIjoiIn0=
} }