PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] Use Laravel routeNotifcationForMail() to send to multiple emails addresses?

 March 01, 2022     laravel-5, laravel-5.3, php, traits     No comments   

Issue

I'm using the Notifiable trait on my Model.

User has comma-separated list of subscribed emails (string).

The documentation and my background reading suggests that this will only route to a single email address.

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the mail channel.
     *
     * @return string
     */
    public function routeNotificationForMail()
    {
        return $this->email_address;
    }
}

Laravel 5.3 Notifications

I've also read Matt Stauffer on Notifications but can't see an answer there.

My NotificationClass->toMail() is as follows.

/**
 * Get the mail representation of the notification.
 *
 * @param Store $store
 * @return mixed
 * @throws Exception
 */
public function toMail(User $user)
{
    return (new MailMessage)->view('notifications.emails.activity-roundup', compact('user'));
}

Solution

I guess you want code below since you can send array (see here):

/**
 * Route notifications for the mail channel.
 *
 * @return string
 */
public function routeNotificationForMail()
{
    return $this->emailsToArray();
}

private function emailsToArray() {
    if (is_null($this->email_addresses)) {
        return $this->email; //default email
    }
    //perform more checks that you need
    return array_map('trim', explode(',', $this->email_addresses))
}


Answered By - Kyslik
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing