quote = $quote; $this->company = $company; } public function handle() { MultiDB::setDB($this->company->db); $contacts = $this->quote->client->contacts; $contacts->each(function ($contact) { $invitation = QuoteInvitation::whereCompanyId($this->quote->company_id) ->whereClientContactId($contact->id) ->whereQuoteId($this->quote->id) ->first(); if (!$invitation && $contact->send) { $ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id); $ii->quote_id = $this->quote->id; $ii->client_contact_id = $contact->id; $ii->save(); } elseif ($invitation && !$contact->send) { $invitation->delete(); } }); } }