user9277271
user9277271

Reputation:

Laravel 5.8: How to pass two arguements to Event & Listener

I'm using Laravel 5.8, and I have created an Event called UserWalletNewTransaction that goes like this:

public $transaction;
public $added_type;

public function __construct($transaction, $added_type)
{
    $this->transaction = $transaction;
    $this->added_type = $added_type;
}

As you can see I have specified two parameters here and these parameters are getting their value from the Controller:

event(new UserWalletNewTransaction($newTransaction, $value_added_type));

And then the Listener which is named UserWalletNotification goes like this:

public function handle(UserWalletNewTransaction $event, $added_type) {

But there is something wrong here since I'm getting this error.

Too few arguments to function App\Listeners\UserWalletNotification::handle(), 1 passed and exactly 2 expected

So how to fix this issue? How can I pass two parameters to Event & Listener properly? I would really appreciate any idea or suggestion from you guys...

Here is the error screenshot:

enter image description here


UPDATE #1:

Result of:

dump($event->added_type);
dd($event->transaction );

enter image description here

Upvotes: 3

Views: 448

Answers (1)

John Lobo
John Lobo

Reputation: 15319

In UserWalltetNotification Listener remove second param from handle method

so

public function handle(UserWalletNewTransaction $event)
{
  
   dump($event->added_type); 
   dd($event->transaction ); 

 
}

if you dd($event); you will get all properties from UserWalletNewTransaction

Upvotes: 1

Related Questions