mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\Document;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class DocumentResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'reference' => $this->reference,
|
|
'status' => (int)$this->status,
|
|
'document_type' => $this->document_type,
|
|
'owner' => new CompanyResource($this->whenLoaded('owner')),
|
|
'files' => $this->when($this->shouldIncludeFiles(false), FileResource::collection($this->files)),
|
|
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A')
|
|
];
|
|
}
|
|
|
|
/**
|
|
* include only when should include file, to be loaded if needed in the UI
|
|
* @param bool $includeFile
|
|
* @return bool
|
|
*/
|
|
private function shouldIncludeFiles(bool $includeFile): bool
|
|
{
|
|
return $includeFile;
|
|
}
|
|
|
|
|
|
}
|