totalShareRateForNode($parent); if ($childTotalShareRate > $parentRate) { throw ValidationException::withMessages([ 'total_share_rate' => ['exceeds_parent'], ]); } if ($childTotalShareRate < 0 || $childTotalShareRate > 100) { throw ValidationException::withMessages([ 'total_share_rate' => ['invalid_range'], ]); } } public function totalShareRateForNode(AgentNode $node): float { $profile = AgentProfile::query()->where('agent_node_id', $node->id)->first(); return $profile !== null ? (float) $profile->total_share_rate : 100.0; } }