【问题标题】:Add locale to laravel resource route将语言环境添加到 laravel 资源路由
【发布时间】:2021-10-15 22:52:27
【问题描述】:

我有以下路线,期望前缀中的语言环境

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

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

// 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.

我的问题是:我应该如何定义我的更新路线以返回正确的 url?

【问题讨论】:

    标签: laravel laravel-blade laravel-routing


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-08-16
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多