company = $company; $this->error = $error; $this->client = $client; $this->amount = $amount; $this->company = $company; $this->settings = $client->getMergedSettings(); } /** * Execute the job. * * @return void */ public function handle() { //Set DB MultiDB::setDb($this->company->db); //iterate through company_users $this->company->company_users->each(function ($company_user) { //determine if this user has the right permissions $methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure','all_notifications']); //if mail is a method type -fire mail!! if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount))->build(); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer($mail_obj); $nmo->company = $this->company; $nmo->to_user = $company_user->user; $nmo->settings = $this->settings; NinjaMailerJob::dispatch($nmo); } }); } }