Reputation: 13162
My listener is like this :
<?php
namespace App\Listeners;
use App\Events\CheckoutOrderEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Mail;
class CheckoutOrderListener
{
public function __construct()
{
//
}
public function handle(CheckoutOrderEvent $event)
{
// dd($event);
$event->data->notify(New \App\Notifications\CheckoutOrder($event->data));
}
}
If I run dd($event), the result is like this :
When executed, there exist error : Call to a member function notify() on array
How to solve it?
Upvotes: 4
Views: 10825
Reputation: 3274
Alright, I was trying to send email to end-user of the application for activating their account (Provided in registration form ) then i got this Error because i was passing "ID" to notify(), actually it should pass whole details of users.
Solved By changing in Http/Controller/Admin/Auth/RegistrationController.php
And that's my Notification Class: app/Notification/UserActivate.php Look at my
__construct() and toMail($notifiable) methods
I hope my mistake helped you. :)
Upvotes: 0
Reputation: 163748
You need to use notify()
on a model with Illuminate\Notifications\Notifiable
trait, but definitely not on an array.
For example, you can get an instance of a User
first:
$user = User::where('email', $event->data['email'])->first();
And then use notify()
:
$user->notify(....)
Upvotes: 2