0

I want create a Model with Notifiable feature,

First,in my controller :

$collection = collect([
    [
    'name' => 'user1',
    'email' => 'user1@gmail.com',
    ],
    [
    'name' => 'user2',
    'email' => 'user2@gmail.com',
    ],
    [
    'name' => 'user1000',
    'email' => 'user1000@gmail.com',
   ],
 ]);

 $u3 = new User3($collection);        

when I return $u3->getEmailList(); , output is :

[{"name":"user1","email":"user1@gmail.com"},{"name":"user2","email":"user2@gmail.com"},{"name":"user1000","email":"user1000@gmail.com"}]   

my class for User3 is:

namespace App;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Notification;
use Illuminate\Notifications\RoutesNotifications;
use Notifications\EmailClientOfAccount;

class User3 extends User
{
   use Notifiable;
   public $emailList;

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

  }

  public  function getEmailList()
    {
     return $this->emailList;
    }
   public function routeNotificationForMail($notification)
   {
    return $this->emailList['email'];
   }
 }

Then, I pass $u3 to Notification as:

Notification::send($u3->getEmailList(), new 

SendMailNotification($template,$subject,$request->input('mailFromTitle'),$attachments));

It show below error:

Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function routeNotificationFor() on array

can you help me for solve this problem,Please?

Thanks in Advance,

//------------------- I correct to :

Notification::send($u3, new SendMailNotification($template,$subject,$request->input('mailFromTitle'),$attachments));

In my My Notification:

public function toMail($notifiable)
{
return  new EmailTo($notifiable,$this->view,$this->topic,$this- 
      >mailFrom,$this->attaches);
}

and in Build():

public function build()
    {

        $email= $this->view($this->view);
        return $email;
    }

But it not work, I dont know where is mistake?

Amir Ali
  • 7
  • 5

1 Answers1

0

Notification send expects a Notifiable object, not the email list itself, if you change it to this, you should get further.

Notification::send($u3, new SendMailNotification($template,$subject,$request->input('mailFromTitle'),$attachments));
mrhn
  • 17,961
  • 4
  • 27
  • 46