From 2269d60f4b2f87a47fbdc6bd6c02448301c89315 Mon Sep 17 00:00:00 2001 From: Belisar Hoxholli Date: Wed, 28 Oct 2020 07:53:09 -0400 Subject: [PATCH 1/2] Add try/catch to mailable boot --- src/Traits/Mailable.php | 52 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Traits/Mailable.php b/src/Traits/Mailable.php index 4155802..31b5877 100644 --- a/src/Traits/Mailable.php +++ b/src/Traits/Mailable.php @@ -15,35 +15,39 @@ trait Mailable */ public static function bootMailable() { - NovaMailTemplate::whereHas('events', function ($query) { - $query->whereModel(get_called_class()); - })->each(function (NovaMailTemplate $novaMailTemplate) { - $novaMailTemplate->events - ->filter(function ($event) { - return collect(config('nova_mail.eventables'))->contains($event->model); - }) - ->each(function ($event) use ($novaMailTemplate) { - if ($event->column) { - $event->model::updated(function ($model) use ($novaMailTemplate, $event) { - if ($model->isDirty($event->column)) { - $value = is_bool($model->{$event->column}) - ? filter_var($event->value, FILTER_VALIDATE_BOOLEAN) - : $event->value; + try { + NovaMailTemplate::whereHas('events', function ($query) { + $query->whereModel(get_called_class()); + })->each(function (NovaMailTemplate $novaMailTemplate) { + $novaMailTemplate->events + ->filter(function ($event) { + return collect(config('nova_mail.eventables'))->contains($event->model); + }) + ->each(function ($event) use ($novaMailTemplate) { + if ($event->column) { + $event->model::updated(function ($model) use ($novaMailTemplate, $event) { + if ($model->isDirty($event->column)) { + $value = is_bool($model->{$event->column}) + ? filter_var($event->value, FILTER_VALIDATE_BOOLEAN) + : $event->value; - if (is_null($event->value) || $model->{$event->column} === $value) { - $model->sendMailTemplate($novaMailTemplate, $event); + if (is_null($event->value) || $model->{$event->column} === $value) { + $model->sendMailTemplate($novaMailTemplate, $event); + } } - } - }); + }); - return; - } + return; + } - $event->model::{$event->name}(function ($model) use ($novaMailTemplate, $event) { - $model->sendMailTemplate($novaMailTemplate, $event); + $event->model::{$event->name}(function ($model) use ($novaMailTemplate, $event) { + $model->sendMailTemplate($novaMailTemplate, $event); + }); }); - }); - }); + }); + } catch (\Illuminate\Database\QueryException $exception) { + \Log::info('Could not bind NovaMailEvents. NovaMail tables might not have migrated yet. This is typical when running fresh migrations during testing or local development.'); + } } /** From 1311606b71acda1eca14a31a627f6fa4ddd72624 Mon Sep 17 00:00:00 2001 From: Belisar Hoxholli Date: Wed, 28 Oct 2020 08:02:35 -0400 Subject: [PATCH 2/2] Break info log Line length --- src/Traits/Mailable.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Traits/Mailable.php b/src/Traits/Mailable.php index 31b5877..05b97f0 100644 --- a/src/Traits/Mailable.php +++ b/src/Traits/Mailable.php @@ -46,7 +46,11 @@ public static function bootMailable() }); }); } catch (\Illuminate\Database\QueryException $exception) { - \Log::info('Could not bind NovaMailEvents. NovaMail tables might not have migrated yet. This is typical when running fresh migrations during testing or local development.'); + \Log::info( + 'Could not bind NovaMailEvents. ' + . 'NovaMail tables might not have migrated yet, ' + . 'typical when running fresh migrations during testing or local development.' + ); } }