Comments (7)
Hello,
A PR is always welcome.
When I was looking through my code for your question, I actually just discovered the bug with hasCustomDomains()
that you fixed above. The same is true for hasCustomSlugs()
.
The whole scoped config feature needs more testing and probably needs to be tweaked here and there.
It would be nice if it could work fluently with the main config.
But that is more complex than it seams I think.
One problem you should double check is if your routes have duplicate names, because you use duplicate locales.
I can give this some deeper thought later today.
from laravel-localized-routes.
I added a $locales
parameter to the LocaleConfig::hasCustomDomains()
function and the LocaleConfig::getSupportedLocales()
.
Here are the updated functions :
public function hasCustomDomains($locales = null): bool
{
$firstValue = array_values($this->getSupportedLocales($locales))[0] ?? '';
$containsDot = strpos($firstValue, '.') !== false;
return $containsDot;
}
public function getSupportedLocales($locales = null): array
{
return $locales ?: $this->supportedLocales;
}
Updated the register function line 28 : $usingDomains = LocaleConfig::hasCustomDomains($locales);
And for now, I can access all my urls from my table above. Do you think I might have broken something ? I will keep testing and give you updates accordingly.
from laravel-localized-routes.
Thanks for your reply, I will continue working on this in the next days/weeks :)
I am now trying to have this urls working :
url | locale |
---|---|
firstwebsite.test/en/category/{translatedSlug} | en |
firstwebsite.test/fr/categorie/{translatedSlug} | fr |
firstwebsite.test/pt/categoria/{translatedSlug} | pt |
secondwebsite.test/category/{translatedSlug} | en |
deuxiemesite.test/categorie/{translatedSlug} | fr |
segundosite.test/categoria/{translatedSlug} | pt |
I added this two routes to my web.php
file :
Route::get(Lang::uri('firstwebsite/shop/category/{$productCategory}'),
[\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('firstwebsite.shop.category');
Route::get(Lang::uri('secondwebsite/shop/category/{$productCategory}'),
[\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('secondwebsite.shop.category');
Translation is working well, I have done a foreach of my categories and urls are ok but I have a 404 when accessing my URLs, I need to figure out why this is happening
EDIT 1 :
When I was looking through my code for your question, I actually just discovered the bug with hasCustomDomains() that you fixed above. The same is true for hasCustomSlugs().
Yes you are right for hasCustomSlugs. Will update this has well.
One problem you should double check is if your routes have duplicate names, because you use duplicate locales.
I think with my route naming i am ok ? firstwebsite.shop.category
& secondwebsite.shop.category
from laravel-localized-routes.
Could you show me a more complete example of your route registration?
And perhaps a screenshot of the php artisan route:list
command?
Trying to understand the flow of your routes.
from laravel-localized-routes.
EDIT : my bad... i removed the $ sign and everything is working well!! Here are the example :
web.php
Route::domain('firstwebsite.test')->group(function () {
Route::localized(function () {
// Home
Route::get('/', [\App\Http\Controllers\HomeController::class, 'index'])->name('firstwebsite.home');
// Shop
Route::get(Lang::uri('firstwebsite/shop/category/{productCategory}'), [\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('firstwebsite.shop.category');
}, ['supported_locales' => ['en', 'fr', 'pt']]
);
});
Route::pattern('secondwebsite', 'secondwebsite.test|deuxiemesite.test|segundosite.test');
Route::domain('{secondwebsite}')->group(function () {
Route::localized(function () {
// Home
Route::get('/', [\App\Http\Controllers\HomeController::class, 'index'])->name('secondwebsite.home');
// Shop
Route::get(Lang::uri('secondwebsite/shop/category/{productCategory}'), [\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('secondwebsite.shop.category');
}, ['supported_locales' => ['en' => 'secondwebsite.test', 'fr' => 'deuxiemesite.test', 'pt' => 'segundosite.test']]
);
});
php artisan route:list
GET|HEAD secondwebsite.test/ en.secondwebsite.home › HomeController@index
GET|HEAD deuxiemesite.test/ fr.secondwebsite.home › HomeController@index
GET|HEAD segundosite.test/ pt.secondwebsite.home › HomeController@index
GET|HEAD segundosite.test/categoria/{productCategory} pt.secondwebsite.shop.category › Shop\CategoryController@show
GET|HEAD deuxiemesite.test/categorie/{productCategory} fr.secondwebsite.shop.category › Shop\CategoryController@show
GET|HEAD secondwebsite.test/category/{productCategory} en.secondwebsite.shop.category › Shop\CategoryController@show
GET|HEAD firstwebsite.test/en en.firstwebsite.home › HomeController@index
GET|HEAD firstwebsite.test/en/category/{productCategory} en.firstwebsite.shop.category › Shop\CategoryController@show
GET|HEAD firstwebsite.test/fr fr.firstwebsite.home › HomeController@index
GET|HEAD firstwebsite.test/fr/categorie/{productCategory} fr.firstwebsite.shop.category › Shop\CategoryController@show
GET|HEAD firstwebsite.test/pt pt.firstwebsite.home › HomeController@index
GET|HEAD firstwebsite.test/pt/categoria/{productCategory} pt.firstwebsite.shop.category › Shop\CategoryController@show
from laravel-localized-routes.
Hello @ivanvermeyen
I was waiting Laravel 11 to start this new website, so I will update this issue according to my finds.
There is an error on the README for Laravel 11 configuration : Target class [CodeZero\Localizer\Middleware\SetLocale] does not exist.
The class is : \CodeZero\LocalizedRoutes\Middleware\SetLocale::class,
from laravel-localized-routes.
Woops, that's what I get for copy-pasting :)
Fixed it now.
Thanks for catching that!
from laravel-localized-routes.
Related Issues (20)
- How to use with Laravel Route Attributes
- Redirect Issue with Octane HOT 3
- Call to undefined method Composer\Util\Platform::getCwd() HOT 5
- Scoped Options supported_locales overridden not working
- Fallback Controller Invalid Route Action HOT 4
- Authentication Breaks on Localized Routes HOT 5
- Route not defined. HOT 3
- * Use Localizer to Detect and Set the Locale HOT 1
- Resource routes HOT 2
- composer-include-files dependency breaks autoload-dev files HOT 3
- How to override route helper? HOT 4
- Share routes with front frameworks like Inertia/VueJS HOT 4
- What's the best way to deal with more complex locales like 'ch-fr'? HOT 1
- Subdomain localized urls HOT 6
- How to remove route parameters? HOT 5
- auto redirect HOT 5
- Redirect request with default locale to omitted locale url HOT 4
- Locale Switcher HOT 2
- Call to a member function getAction() on null HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-localized-routes.