123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Http\Resources\API;
- use App\Models\User;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class ApprovalFlowDetailResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- $nodeUsers = [];
- foreach ($this->nodes as $node) {
- $nodeUsers = [
- ...$nodeUsers,
- ...$node['approval_users'],
- ];
- }
- $users = User::query()->whereIn("id", $nodeUsers)->get()->keyBy("id");
- $nodes = [];
- foreach ($this->nodes as $node) {
- $userObjects = [];
- foreach ($node['approval_users'] as $userId) {
- //$userObjects[] = new UserProfileResource($users->get($userId));
- $userObjects[] = $userId;
- }
- $node['approval_users'] = $userObjects;
- $nodes[] = $node;
- }
- return [
- "id" => $this->id,
- "name" => $this->name,
- "type" => $this->type,
- "object_type" => $this->object_type,
- "object_id" => $this->object_id==0?null:$this->object_id,
- "nodes" => $nodes,
- "status" => $this->status,
- "created_by" => new UserProfileResource($this->createdBy),
- "created_at" => (string)$this->created_at,
- "updated_at" => (string)$this->updated_at,
- ];
- }
- }
|