Check user settings before sending an email notification

brunobg posted 2 weeks ago

I have a receiveEmail boolean field in the User model of a Laravel application. How do I ensure that mail notifications respect this field, and only sends the email to the user if the field is true?

What I want is that this code:

$event = new SomeEvent($somedata);

or this one

Notification::send($users, $event);

where SomeEvent is a class that extends Notification and implements 'mail' on the via() method, only sends an email if the user has allowed emails.

Cameron replied 2 weeks ago

If auth user receiveEmail ?

Cameron replied 2 weeks ago

You could also do the check in the event itself and pass user I’d to the event along with the somedata

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us