exchange/app/Transformers/NewsTransformer.php

28 lines
705 B
PHP

<?php
namespace App\Transformers;
use App\Models\News;
use League\Fractal\TransformerAbstract;
class NewsTransformer extends TransformerAbstract
{
private $locale;
public function __construct($locale)
{
$this->locale = $locale;
}
public function transform(News $news)
{
return [
'id' => $news->id,
'title' => $news->getTranslations('title', [$this->locale]),
'short_description' => $news->getTranslations('short_description', [$this->locale]),
'description' => $news->getTranslations('description', [$this->locale]),
'date' => $news->date,
'image' => url($news->image),
];
}
}