Skip to content

Commit

Permalink
Add try/catch to mailable boot
Browse files Browse the repository at this point in the history
  • Loading branch information
belisarh committed Oct 28, 2020
1 parent c0a1c77 commit 2269d60
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/Traits/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}

/**
Expand Down

0 comments on commit 2269d60

Please sign in to comment.