lotteryAdmin(); abort_if($admin === null, 401); abort_if(! AdminAgentScope::nodeVisibleTo($admin, $agent_node), 403); $profile = AgentProfile::query()->firstOrNew(['agent_node_id' => $agent_node->id]); return ApiResponse::success(app(AgentProfileService::class)->present($profile)); } public function update( AdminAgentProfileUpdateRequest $request, AgentNode $agent_node, AgentProfileService $service, AgentNodeService $agentNodeService, ): JsonResponse { $admin = $request->lotteryAdmin(); abort_if($admin === null, 401); abort_if(! AdminAgentScope::nodeVisibleTo($admin, $agent_node), 403); $parent = $agent_node->parent_id !== null ? AgentNode::query()->find($agent_node->parent_id) : null; $payload = $request->validated(); if ($parent !== null) { $service->assertChildCapabilityGrantsWithinParent($parent, $payload, $admin); } $profile = $service->upsertForNode($agent_node, $payload, $parent); $agentNodeService->syncPrimaryOwnerRoleFromProfile($agent_node, $profile); return ApiResponse::success($service->present($profile)); } }