so this is my route
Route::group(['prefix' => '{locale}'],function(){
Route::get('/','Room_randring_welcom@function0')->name('post')->middleware('setLocale');});
for example, if I chose es in lang or any other language I want to go to
Route::group(['prefix' => '{locale}'],function(){
Route::get('/','Room_randring_welcom@function1')->name('post')->middleware('setLocale');});
**so I can fetch data from another JSON file with another language **
CodePudding user response:
You can do it by editing RouteServiceProvider
, You will find it at root-app/app/Providers/RouteServiceProvider.php
For Laravel <= 7
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapArRoutes(); // Add this line with local name or anything you want.
}
//add function with the new name in my case will be "mapArRoutes"
protected function mapArRoutes()
{
Route::middleware('web')
->prefix('ar') // Here choose a local do you want
->namespace($this->namespace)
->group(base_path('routes/ar.php')); // any name do you want
}
// You will find a function called "mapWebRoutes", edit it.
protected function mapWebRoutes()
{
// This is a default route you just need add perfix with anothoer local do you want
Route::middleware('web')
->prefix('en') // for example i added en
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
Then inside the routes folder/directory add the new file, as my example, it will be ar.php
add all routes to the file related to local.
For Laravel >= 8
...
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
// Add this lines
// Start
Route::middleware('web')
->prefix('ar') // Here choose a local do you want
->namespace($this->namespace)
->group(base_path('routes/ar.php')); // any name do you want
// This is a default route you just need add perfix with anothoer local do you want
Route::middleware('web')
->prefix('en') // for example i added en
->namespace($this->namespace)
->group(base_path('routes/web.php'));
// End
});
}
...
Hope this is clear.
That's all.