php - 更改路线方向取决于所选语言
问题描述
所以这是我的路线
Route::group(['prefix' => '{locale}'],function(){
Route::get('/','Room_randring_welcom@function0')->name('post')->middleware('setLocale');});
例如,如果我在 lang 或任何其他我想去的语言中选择 es
Route::group(['prefix' => '{locale}'],function(){
Route::get('/','Room_randring_welcom@function1')->name('post')->middleware('setLocale');});
**所以我可以使用另一种语言从另一个 JSON 文件中获取数据**
解决方案
您可以通过编辑来完成RouteServiceProvider
,您将在以下位置找到它root-app/app/Providers/RouteServiceProvider.php
对于 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'));
}
然后在路由文件夹/目录中添加新文件,作为我的示例,它将是ar.php
将所有路由添加到与本地相关的文件中。
对于 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
});
}
...
希望这很清楚。
就这样。
推荐阅读
- java - Java Socket 两次读取输入
- apache-spark - 在 Spark 中 datetime.datetime.fromtimestamp 有什么作用?
- c++ - Jenkins 向应用程序控制台发送无效输入
- android - 我可以有多个具有相同项目布局的回收站视图吗?
- asp.net-core-webapi - API NET CORE:错误:400“'I' 是值的无效开始。路径:$ | LineNumber:0 | BytePositionInLine:0。”
- python - 如何修复模块“tensorflow.python.keras.activations”没有属性“get”错误?
- amazon-rds - 连接到 AWS MariaDB 并使用 boto3 运行查询
- java - 尝试执行简单的 servlet 程序时出现错误。映射中是否缺少任何东西?
- node.js - NodeJS Bull queue.add 字符串化数据导致错误
- java - 使用位图时,Android MLKit 人脸检测未检测到人脸