store-manage/app/Http/Resources/WorkflowCheckResource.php

36 lines
1022 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class WorkflowCheckResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$resource = $this->mapResource($this->subject_type);
return [
'check_status' => $this->check_status,
'check_status_text' => $this->check_status?->text(),
'checked_at' => $this->checked_at?->getTimestamp(),
'check_remarks' => (string) $this->check_remarks,
'subject' => $resource ? $resource::make($this->whenLoaded('subject')) : '',
'logs' => WorkflowLogResource::collection($this->whenLoaded('logs')),
];
}
protected function mapResource($key)
{
$map = [
'reimbursements' => ReimbursementResource::class,
];
return data_get($map, $key);
}
}