This commit is contained in:
victor 2020-08-13 14:41:19 +02:00
commit 8bfcfb6441
3 changed files with 20 additions and 7 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Event; use App\Event;
use App\News; use App\News;
use App\Notification;
use App\UserEvent; use App\UserEvent;
use App\User; use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -213,11 +214,22 @@ class EventController extends Controller
$UserEvent->delete(); $UserEvent->delete();
return redirect()->route("events.signups", [ "event" => $id ]); return redirect()->route("events.signups", [ "event" => $id ]);
} else { // Else if you are deleting an event. Then delete all the sign ups AND the event } else { // Else if you are deleting an event. Then delete all the sign ups AND the event
$UserEvent = UserEvent::where('event_id', $id); $UserEvents = UserEvent::where('event_id', $id);
$UserEvent->delete();
$event = Event::find($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(); $event->delete();
return redirect()->route("events.index"); return redirect()->route("events.index");
} }
} }

View File

@ -63,7 +63,7 @@ class NewsController extends Controller
$news->type_id = '1'; $news->type_id = '1';
$news->save(); $news->save();
Helpers::sendNewsNotification($news, User::all()); Helpers::sendNewsNotification($news, User::query()->where("wants_emails", "=", true)->get());
return redirect()->route("news.index"); return redirect()->route("news.index");
} }
@ -77,7 +77,7 @@ class NewsController extends Controller
{ {
$news->save(); $news->save();
Helpers::sendNewsNotification($news, User::all()); Helpers::sendNewsNotification($news, User::query()->where("wants_emails", "=", true)->get());
return $news; return $news;
} }
@ -120,7 +120,7 @@ class NewsController extends Controller
$news->update($data); $news->update($data);
Helpers::sendNewsNotification($news, User::all()); Helpers::sendNewsNotification($news, User::query()->where("wants_emails", "=", true)->get());
return redirect()->route("news.index"); return redirect()->route("news.index");
} }
@ -136,7 +136,7 @@ class NewsController extends Controller
{ {
$news->update(); $news->update();
Helpers::sendNewsNotification($news, User::all()); Helpers::sendNewsNotification($news, User::query()->where("wants_emails", "=", true)->get());
return $news; return $news;
} }

View File

@ -29,6 +29,7 @@ class CreateUsersTable extends Migration
$table->integer("phone")->unique(); $table->integer("phone")->unique();
$table->rememberToken(); $table->rememberToken();
$table->foreignId("resource_id")->nullable()->constrained("resources", "id"); $table->foreignId("resource_id")->nullable()->constrained("resources", "id");
$table->boolean("wants_emails")->default(true);
$table->timestamps(); $table->timestamps();
}); });
} }