Search code examples
phplaravellaravel-4laravel-routing

Laravel rename routing resource path names


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

Solution

  • 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