3

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

Karl Hill
  • 12,937
  • 5
  • 58
  • 95

1 Answers1

1

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

John Lobo
  • 14,355
  • 2
  • 10
  • 20
  • I tried that but `$added_type` variable didn't exist there. I just added an **UPDATE #1** about this. –  Jul 19 '21 at 08:16
  • what you gt if you dd($event->added_type); – John Lobo Jul 19 '21 at 08:17
  • I get this: `""` –  Jul 19 '21 at 08:18
  • @tejoslaeslio look like you are passing null in event(new UserWalletNewTransaction($newTransaction, $value_added_type)); but $value_added_type is null so if you pass value properly then it works as expected – John Lobo Jul 19 '21 at 08:18
  • Would u check this out please: https://stackoverflow.com/questions/68526658/session-still-submitted-after-redirecting-view –  Jul 26 '21 at 08:43