clearAll(); $teamId = get_team_id_from_token(); $both = $request->query->get('both') ?? false; if (is_null($teamId)) { return invalid_token(); } $env = EnvironmentVariable::where('uuid', $request->env_uuid)->first(); if (! $env) { return response()->json([ 'success' => false, 'message' => 'Environment variable not found.', ], 404); } $found_app = $env->resource()->whereRelation('environment.project.team', 'id', $teamId)->first(); if (! $found_app) { return response()->json([ 'success' => false, 'message' => 'Environment variable not found.', ], 404); } $env->delete(); if ($both) { $found_other_pair = EnvironmentVariable::where('application_id', $found_app->id)->where('key', $env->key)->first(); if ($found_other_pair) { $found_other_pair->delete(); } } return response()->json([ 'success' => true, 'message' => 'Environment variable deleted.', ]); } }