From 60cd0ea091af2efa9f76cb1fd629b1676e9c2861 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Sun, 27 Dec 2020 13:34:01 +0100 Subject: [PATCH] Fix bug in news controller --- api/app/Http/Controllers/NewsController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index d47a762..3a58de2 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -288,9 +288,11 @@ QUERY $result = array(); foreach($recent as $item) { - $newsItem = app('db')->select(self::$BASE_SQL . ' AND `news`.`id` = :newsId', ['target' => self::$WEBSITE_TARGET, 'category' => $category, 'secondarycategory' => $secondarycategory, 'newsId' => $item->id])[0]; - $pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $newsItem->id]); - $result[] = new \Model\NewsItem($newsItem, $pictures); + $newsItem = app('db')->select(self::$BASE_SQL . ' AND `news`.`id` = :newsId', ['target' => self::$WEBSITE_TARGET, 'category' => $category, 'secondarycategory' => $secondarycategory, 'newsId' => $item->id]); + if(count($newsItem)) { + $pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $newsItem[0]->id]); + $result[] = new \Model\NewsItem($newsItem[0], $pictures); + } } return response()->json($result);