One solution is to fire the first event a give it the reject value.
// HasBeenUpdated.php
public $rejects;
public function __construct($rejects)
{
$this->rejects = $rejects;
}
fire as event(new HasBeenUpdated($rejects)
You can then listen only once and from there fire subsequent jobs.
// Action1.php (Listener)
public function handle(HasBeenUpdated $event)
{
// pass the rejects value not the event.
dispatch(new SecondAction($event->rejects++)
}
// SecondAction.php (Job)
public $rejects;
public function __construct($rejects)
{
$this->rejects = $rejects;
}
public function handle($rejects)
{
dispatch(new ThirdAction($rejects++)
}
So listen once, and pass the actual data rejects not the event itself to subsequent jobs, each of them can fire other jobs that take in the rejects action. However, for uses like this I would look into the Pipeline pattern, either using Laravel's own implementation:
http://culttt.com/2015/09/28/how-to-use-the-pipeline-design-pattern-in-laravel/
or checking out the League\Pipeline package.
http://pipeline.thephpleague.com/