Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please support customizing the route key. #262

Closed
1 task done
urbsny opened this issue Jul 2, 2021 · 3 comments · Fixed by #265
Closed
1 task done

Please support customizing the route key. #262

urbsny opened this issue Jul 2, 2021 · 3 comments · Fixed by #265
Labels
bug Something isn't working

Comments

@urbsny
Copy link
Contributor

urbsny commented Jul 2, 2021

What happened?

  1. I have the Eloquent model which customized route key.
  2. The model key type is integer and route key type is string.
  3. But GetFromLaravelAPI::class only use key type.

Screenshots and stack traces:

My environment:

  • PHP version (from php -v): 8.0.3
  • Framework (Laravel/Lumen): Laravel
  • Laravel/Lumen version (from composer show laravel/framework or composer show laravel/lumen-framework): v8.49.0
  • Scribe version (from composer show knuckleswtf/scribe): 3.3.2

Additional info:
In my case, I changed GetFromLaravelAPI.php to the following and it worked fine.

$type = $this->normalizeTypeName($argumentInstance->getKeyType());

                    $typeName = $argumentInstance->getKeyName() === $argumentInstance->getRouteKeyName()
                        ? $argumentInstance->getKeyType() : 'string';
                    $type = $this->normalizeTypeName($typeName);
@urbsny urbsny added the bug Something isn't working label Jul 2, 2021
@shalvah
Copy link
Contributor

shalvah commented Jul 2, 2021

Sure, send in a PR. But what does the route key method return for people who haven't defined it for their model?

@urbsny
Copy link
Contributor Author

urbsny commented Jul 2, 2021

Thank you for your quick response. I'll send PR.

what does the route key method return for people who haven't defined it for their model?

Base model return key name. So I don't think it will affect the people who haven't defined it.

https://github.com/laravel/framework/blob/6a3ddf21096b1801d9e7f221f72ae78d90eb3622/src/Illuminate/Database/Eloquent/Model.php#L1786

    public function getRouteKeyName()
    {
        return $this->getKeyName();
    }

@shalvah
Copy link
Contributor

shalvah commented Jul 2, 2021

Cool, should be easy to send in a PR then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants