This commit is contained in:
2020-08-13 14:41:19 +02:00
3 changed files with 20 additions and 7 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Event;
use App\News;
use App\Notification;
use App\UserEvent;
use App\User;
use Illuminate\Http\Request;
@@ -213,11 +214,22 @@ class EventController extends Controller
$UserEvent->delete();
return redirect()->route("events.signups", [ "event" => $id ]);
} else { // Else if you are deleting an event. Then delete all the sign ups AND the event
$UserEvent = UserEvent::where('event_id', $id);
$UserEvent->delete();
$UserEvents = UserEvent::where('event_id', $id);
$event = Event::find($id);
foreach ($UserEvents as $userEvent) {
$notification = new Notification();
$notification->user_id = $userEvent->user_id;
$notification->message = $event->name . " - ";
}
$UserEvents->delete();
$event->delete();
return redirect()->route("events.index");
}
}