0
votes

I want create a Model with Notifiable feature,

First,in my controller :

$collection = collect([
    [
    'name' => 'user1',
    'email' => '[email protected]',
    ],
    [
    'name' => 'user2',
    'email' => '[email protected]',
    ],
    [
    'name' => 'user1000',
    'email' => '[email protected]',
   ],
 ]);

 $u3 = new User3($collection);        

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

[{"name":"user1","email":"[email protected]"},{"name":"user2","email":"[email protected]"},{"name":"user1000","email":"[email protected]"}]   

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?

1
hard to help without an error message.mrhn
I'm sorry, i pass a collection to User3 and return same collection, and pass output that is a collection to first my notification argument, is it right?Amir Ali
Only pass models if you want it done on more than one we can figure that outmrhn

1 Answers

0
votes

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));