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

Handle field name in route parameter #836

Open
blackjak231 opened this issue Jul 22, 2022 · 2 comments
Open

Handle field name in route parameter #836

blackjak231 opened this issue Jul 22, 2022 · 2 comments
Assignees
Labels

Comments

@blackjak231
Copy link

blackjak231 commented Jul 22, 2022

Right now, the current localization system does not handle using field names in route parameters.

Example

Route definitions

french: /ville/{city:slug} --> default language
english: /city/{city:slug}

Using LaravelLocalization::getLocalizedURL() to get the english url, it will return /en/ville/{city:slug}.

After checking, it seems that when getting the attributes it ignores :slug and uses the key city and then tries to find {city} in the translated url to return it.

I wish to not use the route binding on my model as the id and other attributes are used in other places.

Thanks in advance !

@kamranata
Copy link

Same issue

@kskrlinnorth2
Copy link

Is this fixed?

I switched my routes from /page/{model} to /page/{model:slug} and /some-other-page/{model:id} because in some routes I need to fetch same model via slug and in some via ID and package stopped to translate my routes.

Before routes switch I used this fix (which works for my specific use case where all routes that require slug starts with pages.), this isn't long-term solution and it would be good to fix this small bug:

public function getRouteKeyName()
{
    return request()->route() && str_starts_with(request()->route()->getName(), 'pages.') ? 'slug' : 'id';
}

@iwasherefirst2 iwasherefirst2 self-assigned this Dec 4, 2024
@iwasherefirst2 iwasherefirst2 pinned this issue Dec 4, 2024
@iwasherefirst2 iwasherefirst2 unpinned this issue Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants