exchange/app/Transformers/DocumentTransformer.php

27 lines
648 B
PHP

<?php
namespace App\Transformers;
use App\Models\Document;
use Illuminate\Support\Str;
use League\Fractal\TransformerAbstract;
class DocumentTransformer extends TransformerAbstract
{
private $locale;
public function __construct($locale)
{
$this->locale = $locale;
}
public function transform(Document $document)
{
$file = Str::replaceFirst('public/', '', $document->getTranslations('file',[$this->locale])[$this->locale]);
return [
'id' => $document->id,
'title' => $document->getTranslations('title',[$this->locale]),
'file' => url($file),
];
}
}