【发布时间】:2021-09-30 15:39:16
【问题描述】:
我的 Laravel 8 路由似乎有错误。
我的网络路由文件:
Route::get('/{locale}', function ($locale) {
if(!in_array($locale, ['en','nl','ru','uk','fr','de','es','pt','it']))
abort(400);
App::setLocale($locale);
return view('welcome');
});
Route::get('/', function () {
return redirect('/en');
});
Route::middleware(['auth:sanctum'])->get('/dashboard/{locale}', function ($locale) {
if(!in_array($locale, ['en','nl','ru','uk','fr','de','es','pt','it']))
abort(400);
App::setLocale($locale);
return view('dashboard');
})->name('dashboard');
Route::middleware(['auth:sanctum'])->get('/dashboard', function () {
return redirect('/dashboard/en');
});
当去/时,它被重定向到/en。
但是当转到/dashboard 时,它不会重定向到/dashboard/en,而是会出现错误:
Symfony\Component\HttpKernel\Exception\HttpException
http://127.0.0.1:8000/dashboard
可以看出,给出的信息并不多。
有人知道该怎么做吗?
【问题讨论】:
-
顺便说一句,您可以在该路由参数上使用正则表达式模式,这样您就不必在每个需要限制语言环境值的路由中检查它
-
它可能只包含这两条路线。但确实如此。我会记住它的未来:)
标签: php laravel laravel-8 laravel-routing