-
Notifications
You must be signed in to change notification settings - Fork 25
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
Error when Route not defined for this locale #63
Comments
Hey @domihagen, Thanks for the bug report. I'm still thinking about the behaviour we'd like to have since it'd be the same case if you use the For instance: Route::get('test', TestController::class); And then you would still get an error using Laravel's helper If we silence the error in this case, the error might go unnoticed, so I'm not sure that's what I want to do in this case. 🤔 Do you have a real life example of why your route does not exist in a given locale? |
Hey @chinleung, It is clear that you get an error if you call a route that is not defined. But your package offers the possibility to have routes only in certain locales. Maybe it makes sense to be able to pass a fallback, like in the We have those locales: EN (default), NL, FR, IT, ES Real life example: We have some routes (routes are defined for all locales) through which a slug is passed to the controller. The corresponding entry is output on the basis of the slug. If no entry exists in this language, a 404 is returned. Now we have a static route (as in the example above) that contains an SPA. And as long as we do not have all locales live, this route should not be able to be called in the locales that are not publishes yet. We also generate the "hreflang" meta tag, so Google knows in which locale this page is available. Thats why we added the I hope I have explained it clearly. If not, let me know. |
Hey,
Yeah it makes sens to me. 😄 What do you think about having a config to have the helper do one of the following actions if the route doesn't exist:
Or maybe adding a fallback to the helper like you've suggested. |
This sounds good to me 👍 |
Describe the bug
When defining an route that is only available in view locales it throws an Error when calling
localized_route()
To Reproduce
Steps to reproduce the behavior:
Route::multilingual('test/', [TestController::class, 'show'])->name('myTest')->only(['en', 'nl']);
localized_route('myTest')
in a Blade-Filefr
Route [fr.myTest] not defined.
Expected behavior
No Error is thrown
Additional context
As an quick fix i copied the helper function into my own helper file and added following condition:
return Route::has("$locale.$name") ? route("$locale.$name", $parameters, $absolute) : '';
The text was updated successfully, but these errors were encountered: