$this->id, 'name' => $this->name, 'parent_id' => $this->parent_id, 'manager_id' => $this->manager_id, 'children' => $this->when($this->children->isNotEmpty(),function (){ return $this->children->map(function ($child){ return new DepartmentResource($child); })->all(); }), ]; } }