4

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?

moses toh
  • 12,344
  • 71
  • 243
  • 443

2 Answers2

2

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(....)
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • There exist error : `Call to undefined method Illuminate\Database\Query\Builder::notify()` – moses toh Jan 13 '17 at 03:29
  • Look here : http://stackoverflow.com/questions/41627259/how-to-solve-call-to-undefined-method-illuminate-database-query-buildernotify – moses toh Jan 13 '17 at 04:59
0

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. :)

Vipertecpro
  • 3,056
  • 2
  • 24
  • 43