v0.9.13 - Added notifications in events, when an event you're signed up to gets canceled.

This commit is contained in:
frederikpyt
2020-08-14 07:36:42 +02:00
parent bd0d504ab8
commit 9e0f449bd3
8 changed files with 98 additions and 13 deletions
@@ -210,24 +210,24 @@ class EventController extends Controller
public function destroy(Request $request, $id)
{
if ($request->signup != null) { // If input signup is not empty, which has been set when you look at the individuel signup, then delete the user who have signed up for the event
$UserEvent = UserEvent::where('user_id', $request->signup)->where('event_id', $id);
$UserEvent = UserEvent::query()->where('user_id', "=", $request->signup)->where('event_id', "=", $id);
$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
$UserEvents = UserEvent::where('event_id', $id);
$event = Event::find($id);
$userEvents = UserEvent::query()->where('event_id', "=", $id)->get();
$event = Event::query()->find($id);
foreach ($UserEvents as $userEvent) {
foreach ($userEvents as $userEvent) {
$notification = new Notification();
$notification->user_id = $userEvent->user_id;
$notification->message = $event->name . " - ";
$notification->save();
$userEvent->delete();
}
$UserEvents->delete();
$event->delete();
return redirect()->route("events.index");
@@ -298,6 +298,17 @@ class EventController extends Controller
}
return $html;
}
public function deleteNotifications(Request $request){
if($request->ajax()){
foreach (Notification::query()->where("user_id", "=", $request->user_id)->get() as $notification) {
$notification->delete();
}
return "Done";
} else {
return "ERROR";
}
}
}