Notification routing
Opt in by adding RoutesNotificationsViaContacts alongside HasContacts. It resolves Laravel notification destinations from the owner’s primary contacts:
use Illuminate\Notifications\Notifiable;
use RoundlyConsulting\Contacts\Concerns\HasContacts;
use RoundlyConsulting\Contacts\Concerns\RoutesNotificationsViaContacts;
class User extends Model
{
use HasContacts;
use Notifiable;
use RoutesNotificationsViaContacts;
}$user->addEmail('[email protected]', primary: true);
$user->addPhone('+421 900 000 000', primary: true);
$user->routeNotificationForMail(); // '[email protected]'
$user->routeNotificationForVonage(); // '+421900000000'
$user->routeNotificationForTwilio(); // '+421900000000'
$user->notify(new OrderShipped($order)); // your own notification class- routeNotificationForMail() — the primary email.
- routeNotificationForVonage() and routeNotificationForTwilio() — the primary phone.
- Each returns null when there is no primary of that kind, so Laravel simply skips that channel.
Precedence
The trait is intentionally separate from HasContacts and is not applied automatically, because host models often already use Notifiable. When you do add it, these routeNotificationFor*() methods take precedence over Notifiable’s attribute-based routing for the mail, Vonage and Twilio channels.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.