From de44058c76493eee18d02f61ea307c8928fdbc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 21 Jul 2022 16:50:34 +0200 Subject: [PATCH 1/2] `client` include for expenses --- app/Transformers/ExpenseTransformer.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Transformers/ExpenseTransformer.php b/app/Transformers/ExpenseTransformer.php index aa191ab73a..839b2cd033 100644 --- a/app/Transformers/ExpenseTransformer.php +++ b/app/Transformers/ExpenseTransformer.php @@ -15,6 +15,7 @@ use App\Models\Document; use App\Models\Expense; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\SoftDeletes; +use League\Fractal\Resource\Item; /** * class ExpenseTransformer. @@ -31,7 +32,9 @@ class ExpenseTransformer extends EntityTransformer /** * @var array */ - protected $availableIncludes = []; + protected $availableIncludes = [ + 'client', + ]; public function includeDocuments(Expense $expense) { @@ -40,6 +43,17 @@ class ExpenseTransformer extends EntityTransformer return $this->includeCollection($expense->documents, $transformer, Document::class); } + public function includeClient(Expense $expense): ?Item + { + $transformer = new ClientTransformer($this->serializer); + + if (!$expense->client) { + return null; + } + + return $this->includeItem($expense->client, $transformer, Client::class); + } + /** * @param Expense $expense * From 3c313848d89f7016ff8d383f0639bd3cea0c7356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 21 Jul 2022 16:54:47 +0200 Subject: [PATCH 2/2] `vendor` include for expenses --- app/Transformers/ExpenseTransformer.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/Transformers/ExpenseTransformer.php b/app/Transformers/ExpenseTransformer.php index 839b2cd033..13c8d9b748 100644 --- a/app/Transformers/ExpenseTransformer.php +++ b/app/Transformers/ExpenseTransformer.php @@ -13,6 +13,7 @@ namespace App\Transformers; use App\Models\Document; use App\Models\Expense; +use App\Models\Vendor; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\SoftDeletes; use League\Fractal\Resource\Item; @@ -34,6 +35,7 @@ class ExpenseTransformer extends EntityTransformer */ protected $availableIncludes = [ 'client', + 'vendor', ]; public function includeDocuments(Expense $expense) @@ -54,6 +56,17 @@ class ExpenseTransformer extends EntityTransformer return $this->includeItem($expense->client, $transformer, Client::class); } + public function includeVendor(Expense $expense): ?Item + { + $transformer = new VendorTransformer($this->serializer); + + if (!$expense->vendor) { + return null; + } + + return $this->includeItem($expense->vendor, $transformer, Vendor::class); + } + /** * @param Expense $expense *