Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function inferBetterTypesAndExamplesForEloquentUrlParameters(array $pa
// If User model has `id` as an integer, then {id} param should be an integer
$typeHintedEloquentModels = UrlParamsNormalizer::getTypeHintedEloquentModels($endpointData->method);
foreach ($typeHintedEloquentModels as $argumentName => $modelInstance) {
$routeKey = $modelInstance->getRouteKeyName();
$routeKey = $endpointData->route->bindingFields()[$argumentName] ?? $modelInstance->getRouteKeyName();

// Find the param name. In our normalized URL, argument $user might be param {user}, or {user_id}, or {id},
if (isset($parameters[$argumentName])) {
Expand Down Expand Up @@ -116,9 +116,8 @@ protected function inferBetterTypesAndExamplesForEloquentUrlParameters(array $pa
// Now infer.
foreach ($modelInstances as $paramName => $modelInstance) {
// If the routeKey is the same as the primary key in the database, use the PK's type.
$routeKey = $modelInstance->getRouteKeyName();
$type = $modelInstance->getKeyName() === $routeKey
? static::normalizeTypeName($modelInstance->getKeyType()) : 'string';
$routeKey = in_array($paramName, $endpointData->route->bindingFields()) ? $paramName : $modelInstance->getRouteKeyName();;
$type = $modelInstance->getKeyName() === $routeKey ? static::normalizeTypeName($modelInstance->getKeyType()) : 'string';

$parameters[$paramName]['type'] = $type;

Expand Down