Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noop's avatar
Level 5

Change url generated by Route::resource

I'm portuguese but all my models and code is in english, so image you have a user model and what to generate the resources I will get urls like this /users/1 but I want to change the "users" to "utilizadores", how can I do it easily using Route::resources?

I only want to change the url name and keep everything else for example the url to edit a user will be: domain.com/utilizadores/{user}/edit the name of that route will be users.edit.

I have already find a way to do this but it's lots of code, and I want to know if there are a better approach.

At the moment I have this

Route::resource('utilizadores', App\Http\Controllers\UserController::class, [
    'parameters' => [
        'utilizadores' => 'user'
    ],
    'names' => [
        'index' => 'users.index',
        'store' => 'users.store',
        'create' => 'users.create',
        'show' => 'users.show',
        'update' => 'users.update',
        'destroy' => 'users.destroy',
        'edit' => 'users.edit',
    ]
]);
0 likes
4 replies
johnDoe220's avatar

is so simple

Route::resource('users', UsersController::class); // localhost:8000/users/1
to
Route::resource('utilizadores', UsersController::class); // localhost:8000/utilizadores/1
noop's avatar
Level 5

@johnDoe220 No this is not exactly what I want this will change the url to the correct one but it will also change the name of the route from users.index to utilizadores.index, also will modify the name of the parameter for edit and show routes, we will get /utilizadores/{utilizador}/edit instead of /utilizadores/{user}/edit.

With your approach I will need to change controller parameters and the way I call the routes in my code.

I'm searching for a way to change only the url and keep everything else.

noop's avatar
Level 5

@MichalOravec Thank you, that was my approach but the idea of creating an helper to easly create this routes it's smart

Please or to participate in this conversation.