问题描述
我们可以像在Ruby on Rails中一样在Laravel中重命名路由资源路径名吗?
Can we rename routing resource path names in Laravel like in Ruby on Rails?
当前
/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.
Ruby on Rails中的示例;
Example from Ruby on Rails;
scope(path_names: { new: "ekle" }) do
resources :users
end
推荐答案
我知道这是一个老问题.我只是出于历史目的发布此答案:
I know this is an old question. I'm just posting this answer for historical purposes:
Laravel现在可以本地化资源. https://laravel.com/docs/5.5/controllers#restful-localizing -resource-uris
Laravel now has the possibility to localize the resources. https://laravel.com/docs/5.5/controllers#restful-localizing-resource-uris
use Illuminate\Support\Facades\Route;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
Route::resourceVerbs([
'create' => 'crear',
'edit' => 'editar',
]); }
自定义动词后,资源路由注册,例如Route :: resource('fotos','PhotoController') 产生以下URI:
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
这篇关于Laravel重命名路由资源路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!