3 years ago

Pass data from listener to event

Posted 3 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' => [

// 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.