Support the ongoing development of Laravel.io →
Validation Mail

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);
Auth::user()->notify($event);

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.

Last updated 3 years ago.
0

If auth user receiveEmail ?

if(Auth::user()->recieveEmail{
Auth::user()-notify($event);
}
0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

brunobg brunobg Joined 8 Mar 2019

Moderators

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

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.