Reputation:
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:
UPDATE #1:
Result of:
dump($event->added_type);
dd($event->transaction );
Upvotes: 3
Views: 448
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