-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix custom key routing #30
Conversation
Thank you for the contribution @ahmedbally! It will be great to cover this in tests to not break this feature in the future: https://github.com/cybercog/laravel-optimus/blob/master/tests/Traits/OptimusEncodedRouteKeyTest.php |
test for custom key routing
I hope you find it well |
Your code is OK, it's scrutenizer config issue. Thank you for your efforts. I will test it and release then. |
I've tested it, this way we have a breaking change. For example when we have our encoded key stored in This would not work anymore: Route::get('/posts/{public_id:encodedId}', function (Post $post) {
return $post;
}); |
But since originally we haven't used |
Merged it, and will do small tweak in #31 public function resolveRouteBinding($value, $field = null)
{
if ($field === null) {
$field = $this->getRouteKeyName();
}
if (is_string($value) && ctype_digit($value)) {
$value = (int) $value;
}
if (is_int($value) && $field === $this->getRouteKeyName()) {
$value = $this->getOptimus()->decode($value);
}
return $this->where($field, $value)->first();
} It will allow us to explicitly use route key too: Route::get('/posts/{id:encodedId}', function (Post $post) {
return $post;
}); |
this get into my mind when i was taking a shower 😂 😂 😂 |
thank you for your tweaks |
Laravel Optimus v3.7.0 has been released! @ahmedbally you are in contributors list now 🥇 |
If you have a twitter - I could mention you in the release post. |
I am very happy to be in contributors list |
support laravel 8 custom key routing
https://laravel.com/docs/8.x/routing#customizing-the-default-key-name