bart
209
7
General

Pass data from listener to event

Posted 2 years ago by bart

Hey everybody,

I'm using events on my current project and like to pass data from one listener to another by pushing it to the event. But it won't work. Maybe because the listeners are queued. Do you have any idea? Here I go with some code:

// Event service provider
protected $listen = [
        'App\Events\HasBeenUpdated' => [
            'App\Listeners\Action1',
            'App\Listeners\Action2',
        ],
    ];

// HasBeenUpdated.php
public $rejects;

public function __construct()
{
        $this->rejects = 0;
}

// Action1.php
public function handle(HasBeenUpdated $event)
{
        $event->rejects = 1;
}

// Action2.php
public function handle(HasBeenUpdated $event)
{
        dd($event->rejects); // Result is 0 but I expected it to be 1
}

Thanks for ya help!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.