diff --git a/app/Http/Controllers/EventsController.php b/app/Http/Controllers/EventsController.php index 9a321fc..e12d8b8 100644 --- a/app/Http/Controllers/EventsController.php +++ b/app/Http/Controllers/EventsController.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers; use App\Events\EventParticipationCancelled; use App\Mail\EventParticipationCancelledMail; -use App\Mail\ValidateMail; use App\Models\Events; use App\Models\Task; use Illuminate\Http\Request; @@ -12,6 +11,7 @@ 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 @@ -89,6 +89,8 @@ class EventsController extends Controller try { $event = Events::with('tasks.users')->find($id); + Log::info($event); + Log::info($event->tasks); if (!$event) { return response()->json(['message' => 'Event not found'], 404); @@ -98,21 +100,22 @@ class EventsController extends Controller return $task->users; })->unique('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)); + if (Carbon::now()->lessThanOrEqualTo($event->end)) { + 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();