firstOrFail(); $data['receive_emails'] = $invitation->contact->is_locked ? false : true; $data['company'] = $invitation->company; return $this->render('generic.email_preferences', $data); } public function update(string $entity, string $invitation_key, Request $request): \Illuminate\Http\RedirectResponse { $class = "\\App\\Models\\" . ucfirst(Str::camel($entity)) . 'Invitation'; $invitation = $class::withTrashed()->where('key', $invitation_key)->firstOrFail(); $invitation->contact->is_locked = $request->has('receive_emails') ? false : true; $invitation->contact->push(); if ($invitation->contact->is_locked) { $nmo = new NinjaMailerObject(); $nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($invitation->contact, $invitation->contact->company))->build()); $nmo->company = $invitation->contact->company; $nmo->to_user = $invitation->contact->company->owner(); $nmo->settings = $invitation->contact->company->settings; NinjaMailerJob::dispatch($nmo); } return back()->with('message', ctrans('texts.updated_settings')); } }