From 54500cd558b15f554d6adb631fb0990c93bedecc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Mar 2020 23:53:00 +1100 Subject: [PATCH] Fixes for Email Controller (#3562) * Fixes for notifications * Fixes for email controller --- app/Http/Controllers/EmailController.php | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index b1dab80900..e629be7004 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -14,13 +14,23 @@ namespace App\Http\Controllers; use App\Helpers\Email\InvoiceEmail; use App\Http\Requests\Email\SendEmailRequest; use App\Jobs\Invoice\EmailInvoice; +use App\Models\Credit; +use App\Models\Invoice; +use App\Models\Quote; use App\Notifications\SendGenericNotification; +use App\Transformers\CreditTransformer; +use App\Transformers\InvoiceTransformer; +use App\Transformers\QuoteTransformer; use App\Utils\Traits\MakesHash; class EmailController extends BaseController { use MakesHash; + protected $entity_type = Invoice::class ; + + protected $entity_transformer = InvoiceTransformer::class ; + public function __construct() { parent::__construct(); @@ -115,9 +125,25 @@ class EmailController extends BaseController }); - $entity->service()->markSent()->save(); + 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); - return $this->itemResponse($entity); } }