more item tax api fix

This commit is contained in:
Denis Duliçi 2021-01-02 12:05:11 +03:00
parent b060480179
commit c8976b56cf
2 changed files with 46 additions and 3 deletions

View File

@ -2,9 +2,8 @@
namespace App\Transformers\Common; namespace App\Transformers\Common;
use App\Transformers\Setting\Category;
use App\Transformers\Setting\Tax;
use App\Models\Common\Item as Model; use App\Models\Common\Item as Model;
use App\Transformers\Setting\Category;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
class Item extends TransformerAbstract class Item extends TransformerAbstract
@ -46,7 +45,7 @@ class Item extends TransformerAbstract
return $this->null(); return $this->null();
} }
return $this->collection($model->taxes, new Tax()); return $this->collection($model->taxes, new ItemTax());
} }
/** /**

View File

@ -0,0 +1,44 @@
<?php
namespace App\Transformers\Common;
use App\Models\Common\ItemTax as Model;
use App\Transformers\Setting\Tax;
use League\Fractal\TransformerAbstract;
class ItemTax extends TransformerAbstract
{
/**
* @var array
*/
protected $defaultIncludes = ['tax'];
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $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());
}
}