From b6f4fdb1383d1412c75dc137878994f211f3dded Mon Sep 17 00:00:00 2001 From: Anders Date: Mon, 31 Aug 2020 12:48:59 +0200 Subject: [PATCH] v0.10.18 - When deleting a menu, guide or event - The news according to the menu,guide or event will also get deleted (correctly now) --- .../app/Http/Controllers/EventController.php | 5 ++--- .../app/Http/Controllers/GuideController.php | 15 ++++++++------- .../app/Http/Controllers/MenuPlanController.php | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/skolehjem/app/Http/Controllers/EventController.php b/skolehjem/app/Http/Controllers/EventController.php index 86385db..50e72b4 100644 --- a/skolehjem/app/Http/Controllers/EventController.php +++ b/skolehjem/app/Http/Controllers/EventController.php @@ -233,9 +233,8 @@ class EventController extends Controller $userEvent->delete(); } - $news = News::query()->where("type_id", "=", "3")->where("arrangement_id", "=", $event->id)->first(); - if($news !== null) - $news->delete(); + $news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->where("type", "=", "Activity")->where("arrangement_id", "=", $id); + $news->delete(); $event->delete(); diff --git a/skolehjem/app/Http/Controllers/GuideController.php b/skolehjem/app/Http/Controllers/GuideController.php index c75fb96..2648f8b 100644 --- a/skolehjem/app/Http/Controllers/GuideController.php +++ b/skolehjem/app/Http/Controllers/GuideController.php @@ -159,17 +159,18 @@ class GuideController extends Controller /** * Remove the specified resource from storage. * - * @param Guide $guide + * @param Guide $id * @return \Illuminate\Http\Response */ - public function destroy($guide) + public function destroy($id) { - $guide = Guide::find($guide); - $news = News::query()->where("type_id", "=", "4")->where("arrangement_id", "=", $guide->id)->first(); - - if($news !== null) - $news->delete(); + // Find the guide you want to remove + $guide = Guide::find($id); + // Find the news the you made when creating the guide (if there is a news) + $news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->where("type", "=", "Guide")->where("arrangement_id", "=", $id); + //Delete the news or/and guide + $news->delete(); $guide->delete(); diff --git a/skolehjem/app/Http/Controllers/MenuPlanController.php b/skolehjem/app/Http/Controllers/MenuPlanController.php index c6622c5..0fd4087 100644 --- a/skolehjem/app/Http/Controllers/MenuPlanController.php +++ b/skolehjem/app/Http/Controllers/MenuPlanController.php @@ -193,7 +193,13 @@ class MenuPlanController extends Controller */ public function destroy($id) { + // Find the menu you want to remove $menuplan = MenuPlan::find($id); + // Find the news the you made when creating the menu (if there is a news) + $news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->where('type', '=', 'Menu')->where('arrangement_id', '=', $id); + + //Delete the news or/and menu + $news->delete(); $menuplan->delete(); return redirect()->route("menu-plans.index"); }