I have to setup a multi-language application with Laravel 11, this is the first time that I use multi-language feature in laravel, I will not use any package, I will set it manually, so I prepared the web.php file like this :
Route::group(['middleware' => ['setLocale']], function () {
Route::get('/products/{slug}', [ProductController::class, 'fetchProduct']);
});
Route::group(['middleware' => ['setLocale'], 'prefix' => '{locale?}', 'where' => ['locale' => 'en|fr|de|jp']], function () {
Route::get('/', LandingController::class);
Route::get('/products/{slug}', [ProductController::class, 'fetchProduct']);
});
When I access to ‘/products/fr/exemple-product’ it works but when I tried to acces to the default route like this : ‘/products/exemple-product’ it deosn’t work and handle an error:
Too few arguments to function App\Http\Controllers\Front\ProductController::fetchProduct(), 1 passed in C:\...\ControllerDispatcher.php on line 46 and exactly 2 expected
this is the definiion of the fetchProduct
method :
public function fetchProduct($locale = null, $slug) {dd($slug');}
even if I setted $locale
to null but it deos’t work, can you please tell me what is the problem?