dongle7637 2015-01-06 19:59
浏览 563
已采纳

Laravel重命名路由资源路径名称

Can we rename routing resource path names in Laravel like in Ruby on Rails?

Current

/users/create  ->  UsersController@create
/users/3/edit  ->  UsersController@edit

.. I want like this;

/users/yeni  ->  UsersController@create
/users/3/duzenle  ->  UsersController@edit

I want to do this for localization.


Example from Ruby on Rails;

scope(path_names: { new: "ekle" }) do
  resources :users
end
  • 写回答

5条回答 默认 最新

  • du13932014807 2017-10-31 15:14
    关注

    I know this is an old question. I'm just posting this answer for historical purposes:

    Laravel now has the possibility to localize the resources. https://laravel.com/docs/5.5/controllers#restful-localizing-resource-uris

    Localizing Resource URIs By default, Route::resource will create resource URIs using English verbs. If you need to localize the create and edit action verbs, you may use the Route::resourceVerbs method. This may be done in the boot method of your AppServiceProvider:

    use Illuminate\Support\Facades\Route;
    
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    
    public function boot() {
        Route::resourceVerbs([
            'create' => 'crear',
            'edit' => 'editar',
        ]); } 
    

    Once the verbs have been customized, a resource route registration such as Route::resource('fotos', 'PhotoController') will produce the following URIs:

    /fotos/crear
    
    /fotos/{foto}/editar
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮