Explorar o código

Wrap in try/catch

shalvah %!s(int64=3) %!d(string=hai) anos
pai
achega
b431bc62e1

+ 7 - 2
src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php

@@ -69,9 +69,14 @@ class GetFromLaravelAPI extends Strategy
                     $type = $this->normalizeTypeName($typeName);
                     $parameters[$paramName]['type'] = $type;
 
-                    $example  = $argumentInstance::first()->id ?? null;
+                    // Try to fetch an example ID from the database
+                    try {
+                        $example = $argumentInstance::first()->id ?? null;
+                    } catch (\Throwable $e) {
+                        $example = null;
+                    }
 
-                    if($example === null) {
+                    if ($example === null) {
                         // If the user explicitly set a `where()` constraint, use that to refine examples
                         $parameterRegex = $endpointData->route->wheres[$paramName] ?? null;
                         $example = $parameterRegex