Create unassignUser, unassignSelf methods and Bruno requests. Add call events when needed

This commit is contained in:
2026-01-11 19:03:58 +01:00
parent 234717b23c
commit ab1df4d692
6 changed files with 181 additions and 10 deletions
+21 -3
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Events\EventParticipationCancelled;
use App\Models\Events;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
@@ -83,12 +84,29 @@ class EventsController extends Controller
}
try {
$event = Events::with('tasks.users')->find($id);
if (!$event) {
return response()->json(['message' => 'Event not found'], 404);
}
$participants = $event->tasks->flatMap(function ($task) {
return $task->users;
})->unique('id');
foreach ($participants as $user) {
broadcast(new EventParticipationCancelled(
$user->id,
$event
));
}
$event = Events::find($id);
$event->delete();
return response()->json(["message" => "Event deleted"]);
return response()->json(["message" => "Event deleted and participants notified"]);
} catch (\Exception $e) {
Log::info($e->getMessage());
Log::error("Event delete error: " . $e->getMessage());
return response()->json(['message' => "Server error"], 500);
}
}