将语言环境添加到 laravel 资源路由

Add locale to laravel resource route

我有以下路由,期望前缀中的区域设置

Route::group(['prefix' => '{locale}/admin', 'where' => ['locale' => '[a-zA-Z]{2}'], 'middleware' => 'setlocale'], function() {
    Route::resource('/profile', 'Admin\ProfileController', ['except' => ['edit', 'create', 'destroy', 'show', 'store']]);
});

最终路线应该是这样的:

www.example.com/en/admin/profile
and
www.example.com/en/admin/profile/1

虽然我可以获得索引路由 www.example.com/en/admin/profile,但我无法获取更新路由 www.example.com/en/admin/profile/1 而我有这个

www.example.com/1/admin/profile/en

这是我的路由在 blade 中的定义方式

// Return index route correctly
{{route('profile.index', app()->getLocale())}}

//And 

{{route('profile.update', [$user->id, app()->getLocale()])}}
// Return update route wrong as I mentioned above.

我的问题是: 我应该如何定义我的更新路由到 return 正确 url?

您传递的参数顺序错误。您需要先发送locale,然后再发送$user->id

{{ route('profile.update', [app()->getLocale(), $user->id]) }}