ApprovalFlowResource.php 981 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Models\Project;
  4. use Illuminate\Http\Request;
  5. use App\Models\Enums\ApprovalFlowType;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class ApprovalFlowResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @return array<string, mixed>
  13. */
  14. public function toArray(Request $request): array
  15. {
  16. $projecName=$this->object_type==ApprovalFlowType::TASK->value?null:Project::query()->where('id',$this->object_id)->first();
  17. return [
  18. 'id' => $this->id,
  19. 'name' => $this->name,
  20. 'type' => $this->type,
  21. 'object_type' => $this->object_type,
  22. 'object_id' => $this->object_id==0?null:$this->object_id,
  23. 'link_project'=>$projecName==null?null:$projecName->name,
  24. 'created_at' => (string)$this->created_at,
  25. 'created_by' => new UserProfileResource($this->createdBy),
  26. ];
  27. }
  28. }