invoice = $invoice; } public function handle() { $contacts = $this->invoice->client->contacts; $contacts->each(function ($contact) { $invitation = InvoiceInvitation::whereCompanyId($this->invoice->company_id) ->whereClientContactId($contact->id) ->whereInvoiceId($this->invoice->id) ->first(); if(!$invitation && $contact->send_invoice) { $ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id); $ii->invoice_id = $this->invoice->id; $ii->client_contact_id = $contact->id; $ii->save(); } else if($invitation && !$contact->send_invoice) { $invitation->delete(); } }); } }