Open domihagen opened 2 years ago
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 route
helper on a non registered route.
For instance:
Route::get('test', TestController::class);
And then you would still get an error using Laravel's helper route('test');
since we forgot to name the route with ->name
.
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 current_route()
helper?
We have those locales: EN (default), NL, FR, IT, ES Published locales: EN & NL
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 ->only(['en', 'nl'])
to the static route, to prevent generating this tag and Google from indexing this Page.
I hope I have explained it clearly. If not, let me know.
Hey,
I hope I have explained it clearly. If not, let me know.
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) : '';