Laravel – send Email by Notification

fmchanprogrammingLeave a Comment

First we create a trait for user. Visit (Traits in PHP and Laravel) if you want to learn trait.

Also we make a function in the trait to call the notification event.

trait SendEmail {
    public function sendEmailNotification($name) {
        $this->notify(new EmailNotification($name));
class User {
    use SendEmail,

send a email inside the notification

class EmailNotification extends Notification {
    use Queueable;

    public $name;

    public function __construct($name) {
        $this->name = $name;

    public function toMail($notifiable) {
        return (new MailMessage())->line($this->name);

Finally, send a email with variable by a user


And you can also change the mail template


Leave a Reply

Your email address will not be published. Required fields are marked *