Description
- Laravel Version: 8.34.0
- PHP Version: 7.4.18
Description:
In my project I have the option to send an email if the event ends successfully and the option to send if a failure occurs, using. The user can choose both or neither.
I do an if to check the user's choice, like this:
if ($schedule->sendmail_success) {
$event->emailOutputTo($schedule->email);
}
if ($schedule->sendmail_error) {
$event->emailOutputOnFailure($schedule->email);
}
If the user wants to receive all outputs and there is a failure, the email is sent twice, the emailOutputTo
is called twice. (In this case it is simple to solve, just use the emailOutputTo
because this method doesn't care about the result).
But, if the user wants to receive only the successful outputs, and an error occurs in the process, he receives the email anyway, because the emailOutputTo
does not make this distinction.
Possible solution
To solve this little problem I believe an emailOutputOnSuccessTo
method solves it. So the class would have 3 methods to send email with the output:
emailOutputTo
-> send the output regardless of the result
emailOutputOnFailureTo
-> send output only on failure
emailOutputOnSuccessTo
-> send output only on success