moses toh
moses toh

Reputation: 13162

How to solve Call to a member function notify() on array? (laravel 5.3)

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 :

enter image description here

When executed, there exist error : Call to a member function notify() on array

How to solve it?

Upvotes: 4

Views: 10825

Answers (2)

Vipertecpro
Vipertecpro

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. enter image description here

Solved By changing in Http/Controller/Admin/Auth/RegistrationController.php

enter image description here

And that's my Notification Class: app/Notification/UserActivate.php Look at my

__construct() and toMail($notifiable) methods

enter image description here

I hope my mistake helped you. :)

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

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

Related Questions