Okoroafor Chukwuemeka
Okoroafor Chukwuemeka

Reputation: 152

How to send laravel notification to a custom email

I have a laravel application, I send notifications to a user when he registers. I use the notify() on the model. But I have an issue, How do i send a notification to a custom email address? the same notification.

Here's what i have:

   `$admin = Admin::find(1);

    $admin->email = '[email protected]';

    $admin->notify((new NewUserRegistered($user))->delay($when));

    $user->notify((new UserRegistered($user))->delay($when));`

i get a user model instance, and customize the email to input the custom email... However, the email sends to the original mail on the model and ignores the edit. How do i do this please?

Upvotes: 2

Views: 1751

Answers (2)

Abdul Rehman
Abdul Rehman

Reputation: 192

Here the code snippet you can use for sending the notification directly to an email address without creating the User or without having the User in the database.

Notification::route('mail', '[email protected]')->notify(new InvoicePaid($invoice));

Upvotes: 5

Bara' ayyash
Bara' ayyash

Reputation: 1935

As a work around, you can save the model before sending the message

$admin->email = '[email protected]';
$admin->save();

after that you can retrieve the email as it was

Upvotes: 1

Related Questions