more item tax api fix
This commit is contained in:
parent
b060480179
commit
c8976b56cf
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
44
app/Transformers/Common/ItemTax.php
Normal file
44
app/Transformers/Common/ItemTax.php
Normal 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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user