diff --git a/app/Transformers/Common/Item.php b/app/Transformers/Common/Item.php index 873d877d9..a554e6ded 100644 --- a/app/Transformers/Common/Item.php +++ b/app/Transformers/Common/Item.php @@ -2,9 +2,8 @@ namespace App\Transformers\Common; -use App\Transformers\Setting\Category; -use App\Transformers\Setting\Tax; use App\Models\Common\Item as Model; +use App\Transformers\Setting\Category; use League\Fractal\TransformerAbstract; class Item extends TransformerAbstract @@ -46,7 +45,7 @@ class Item extends TransformerAbstract return $this->null(); } - return $this->collection($model->taxes, new Tax()); + return $this->collection($model->taxes, new ItemTax()); } /** diff --git a/app/Transformers/Common/ItemTax.php b/app/Transformers/Common/ItemTax.php new file mode 100644 index 000000000..0275b8e9e --- /dev/null +++ b/app/Transformers/Common/ItemTax.php @@ -0,0 +1,44 @@ + $model->id, + 'company_id' => $model->company_id, + 'item_id' => $model->item_id, + 'tax_id' => $model->tax_id, + 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '', + 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '', + ]; + } + + /** + * @param Model $model + * @return mixed + */ + public function includeTax(Model $model) + { + if (!$model->tax) { + return $this->null(); + } + + return $this->item($model->tax, new Tax()); + } +}