From fdab4ee5308c3da692c33d7a709728ffa42ade9a Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Sun, 11 Apr 2021 14:32:58 -0400 Subject: [PATCH] Fix email for news not going out (#1131) --- app/Notifications/EventHandler.php | 22 +++++++++++-------- app/Notifications/Messages/NewsAdded.php | 2 +- .../notifications/mail/news/news.blade.php | 6 +---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/Notifications/EventHandler.php b/app/Notifications/EventHandler.php index 48a9753d..ea755258 100644 --- a/app/Notifications/EventHandler.php +++ b/app/Notifications/EventHandler.php @@ -50,10 +50,16 @@ class EventHandler extends Listener { $admin_users = User::whereRoleIs('admin')->get(); - try { - Notification::send($admin_users, $notification); - } catch (Exception $e) { - Log::emergency('Error emailing admins, malformed email='.$e->getMessage()); + foreach ($admin_users as $user) { + if (empty($user->email)) { + continue; + } + + try { + Notification::send([$user], $notification); + } catch (Exception $e) { + Log::emergency('Error emailing admin ('.$user->email.'). Error='.$e->getMessage()); + } } } @@ -66,7 +72,7 @@ class EventHandler extends Listener try { $user->notify($notification); } catch (Exception $e) { - Log::emergency('Error emailing admins, malformed email='.$e->getMessage()); + Log::emergency('Error emailing user, '.$user->ident.'='.$user->email.', error='.$e->getMessage()); } } @@ -91,10 +97,8 @@ class EventHandler extends Listener Log::info('Sending notification to '.$users->count().' users'); - try { - Notification::send($users, $notification); - } catch (Exception $e) { - Log::emergency('Error emailing admins, malformed email='.$e->getMessage()); + foreach ($users as $user) { + $this->notifyUser($user, $notification); } } diff --git a/app/Notifications/Messages/NewsAdded.php b/app/Notifications/Messages/NewsAdded.php index 660d366d..c4ee6351 100644 --- a/app/Notifications/Messages/NewsAdded.php +++ b/app/Notifications/Messages/NewsAdded.php @@ -22,7 +22,7 @@ class NewsAdded extends Notification $this->news = $news; $this->setMailable( $news->subject, - 'notifications.mail.news', + 'notifications.mail.news.news', ['news' => $news] ); } diff --git a/resources/views/notifications/mail/news/news.blade.php b/resources/views/notifications/mail/news/news.blade.php index ffce5615..69283c72 100644 --- a/resources/views/notifications/mail/news/news.blade.php +++ b/resources/views/notifications/mail/news/news.blade.php @@ -1,11 +1,7 @@ @component('mail::message') # {{ $news->subject }} - $news->body - - @component('mail::button', ['url' => route('frontend.pireps.show', [$pirep->id])]) - View PIREP - @endcomponent + {{ $news->body }} Thanks,
{{ config('app.name') }}