mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 20:44:19 +00:00
59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Models\File;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class FileTransformer extends TransformerAbstract
|
|
{
|
|
|
|
|
|
/**
|
|
* @var bool|mixed|null
|
|
*/
|
|
private bool $loadMediumAndOriginal;
|
|
|
|
public function __construct($loadMediumAndOriginal = false)
|
|
{
|
|
$this->loadMediumAndOriginal = $loadMediumAndOriginal;
|
|
}
|
|
|
|
/**
|
|
* AA Array of possible includes for file model
|
|
* @var array
|
|
*/
|
|
protected array $availableIncludes = [
|
|
|
|
];
|
|
|
|
/**
|
|
* Transform File
|
|
* @param File $file
|
|
* @return array
|
|
*/
|
|
public function transform(File $file): array
|
|
{
|
|
if ($this->loadMediumAndOriginal) {
|
|
$files = $file->file;
|
|
$newObject = $files->file_info = collect($files->file_info)
|
|
->filter(function ($file) {
|
|
return !isset($file->large) && !isset($file->small);
|
|
})
|
|
->values()
|
|
->all();
|
|
|
|
} else {
|
|
$newObject = $file->file;
|
|
}
|
|
|
|
|
|
return [
|
|
'id' => $file->id,
|
|
'file' => $newObject,
|
|
'type' => (int)$file->file_type,
|
|
];
|
|
|
|
}
|
|
}
|