2022-11-28 19:17:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
|
|
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
|
|
|
|
|
|
class CategoryTransformer extends TransformerAbstract
|
|
|
|
|
{
|
|
|
|
|
private $locale;
|
2022-12-05 06:12:09 +00:00
|
|
|
private $type;
|
2022-11-28 19:17:00 +00:00
|
|
|
|
2022-12-05 06:12:09 +00:00
|
|
|
public function __construct($locale, $type)
|
2022-11-28 19:17:00 +00:00
|
|
|
{
|
|
|
|
|
$this->locale = $locale;
|
2022-12-05 06:12:09 +00:00
|
|
|
$this->type = $type;
|
2022-11-28 19:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-05 06:12:09 +00:00
|
|
|
public function transform($category)
|
2022-11-28 19:17:00 +00:00
|
|
|
{
|
2022-12-05 06:12:09 +00:00
|
|
|
return $this->type == 'trading' ? [
|
|
|
|
|
'id' => $category->id,
|
2022-12-06 05:30:38 +00:00
|
|
|
'title' => $category->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
|
2022-12-05 06:12:09 +00:00
|
|
|
] : [
|
2022-11-28 19:17:00 +00:00
|
|
|
'id' => $category->id,
|
2022-12-06 05:30:38 +00:00
|
|
|
'title' => $category->getTranslations('title', [$this->locale])[$this->locale] ?? '-',
|
2022-12-05 06:12:09 +00:00
|
|
|
'type' => $category->type,
|
2022-11-28 19:17:00 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|