36 lines
967 B
PHP
36 lines
967 B
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Models\Trading;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class TradingTransformer extends TransformerAbstract
|
|
{
|
|
private $type;
|
|
|
|
public function __construct($type = '')
|
|
{
|
|
$this->type = $type;
|
|
}
|
|
|
|
public function transform(Trading $trading)
|
|
{
|
|
return $this->type == 'selected' ? [
|
|
'id' => $trading->id,
|
|
'title' => $trading->title,
|
|
'price' => $trading->price,
|
|
'old_price' => $trading->old_price,
|
|
'price_change' => $trading->price_change,
|
|
'currency' => $trading->currency,
|
|
'all_prices' => $trading->all_prices,
|
|
] : [
|
|
'id' => $trading->id,
|
|
'title' => $trading->title,
|
|
'price' => $trading->price,
|
|
'old_price' => $trading->old_price,
|
|
'price_change' => $trading->price_change,
|
|
'currency' => $trading->currency,
|
|
];
|
|
}
|
|
} |