Merge branch dev into features/notifications

This commit is contained in:
Giovanni committed 2026-03-19 09:56:35 +01:00
commit 75d80985ff
30 files changed
+1012 -80

No files matched your search

+24 -11
View File
@@ -5,11 +5,14 @@ namespace App\Http\Controllers;
use App\Events\EventParticipationCancelled;
use App\Models\Event;
use App\Models\Notification;
use App\Mail\EventParticipationCancelledMail;
use App\Models\Task;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Carbon\Carbon;
class EventsController extends Controller
@@ -96,22 +99,32 @@ class EventsController extends Controller
return $task->users;
})->unique('id');
$notification = Notification::create([
'content' => "L'événement '{$event->name}' a été supprimé. Vous n'y participez donc plus."
]);
$notification->users()->attach($participants->pluck('id'));
foreach ($participants as $user) {
broadcast(new EventParticipationCancelled(
$user->id,
$event
));
if (Carbon::now()->lessThanOrEqualTo($event->end)) {
$notification = Notification::create([
'content' => "L'événement '{$event->name}' a été supprimé. Vous n'y participez donc plus."
]);
$notification->users()->attach($participants->pluck('id'));
foreach ($participants as $user) {
broadcast(new EventParticipationCancelled(
$user->id,
$event
));
$data = [
'name' => $user->name,
'lastname' => $user->lastname,
'eventName' => $event->name,
'start' => $event->start,
'end' => $event->end,
];
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
}
}
$event->delete();
return response()->json(["message" => "Event deleted and participants notified"]);
} catch (\Exception $e) {
Log::error("Event delete error: " . $e->getMessage());
return response()->json(['message' => "Server error"], 500);