$this->id, 'name' => $this->name, 'parent_id' => $this->parent_id, 'count' => $this->users->count(), 'manager_id' => $this->manager_id ? new UserProfileResource($this->byManager) : 0, 'children' => $this->when($this->children->isNotEmpty(),function (){ return $this->children->map(function ($child){ return new DepartmentResource($child); })->all(); }), 'created_at' => (string)$this->created_at, ]; } }