input('entity'); $entity_obj = $entity::find($request->input('entity_id')); $subject = $request->input('subject'); $body = $request->input('body'); $entity_string = strtolower(class_basename($entity_obj)); $entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj) { if ($invitation->contact->send_email && $invitation->contact->email) { $when = now()->addSeconds(1); $invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when)); } }); /*Only notify the admin ONCE, not once per contact/invite*/ $invitation = $entity_obj->invitations->first(); EntitySentMailer::dispatch($invitation, $entity_string, $entity_obj->user, $invitation->company); if ($this instanceof Invoice) { $this->entity_type = Invoice::class ; $this->entity_transformer = InvoiceTransformer::class ; } if ($this instanceof Quote) { $this->entity_type = Quote::class ; $this->entity_transformer = QuoteTransformer::class ; } if ($this instanceof Credit) { $this->entity_type = Credit::class ; $this->entity_transformer = CreditTransformer::class ; } $entity_obj->service()->markSent()->save(); return $this->itemResponse($entity_obj); } }