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

Konstruktionsplan's avatar

Resource-Routing 🤞🏻

Hello! 🌙

    Route::resources([
        'clients' => ClientController::class,
		//and so on...
    ]);

I want to change "clients" to "kunden" without make changes something like "kunden.create" in the view.

Also in Code "clients.create" and in the url "kunden/erstellen".

Thanks!

0 likes
8 replies
MichalOravec's avatar
Level 75

Sometimes read the documentation

Route::resource('kunden', ClientController::class)->names([
    'index' => 'clients.index',
    'create' => 'clients.create',
    'store' => 'clients.store',
    'show' => 'clients.show',
    'edit' => 'clients.edit',
    'update' => 'clients.update',
    'destroy' => 'clients.destroy'
])->parameters([
    'kunden' => 'client'
]);

https://laravel.com/docs/8.x/controllers#restful-naming-resource-routes

https://laravel.com/docs/8.x/controllers#restful-naming-resource-route-parameters

/**
 * Define your route model bindings, pattern filters, etc.
 *
 * @return void
 */
public function boot()
{
    Route::resourceVerbs([
        'create' => 'erstellen',
        'edit' => 'bearbeiten'
    ]);

    // ...
}

https://laravel.com/docs/8.x/controllers#restful-localizing-resource-uris

But probably better will be do it manually.

Or create a helper something like this

if (! function_exists('route_resource')) {
    function route_resource($route, $parameter, $except = [], $name = null)
    {
        if (! $name) {
            $name = Str::kebab(Str::plural($parameter));
        }

        return [
            'names' => [
                'index' => "{$name}.index",
                'create' => "{$name}.create",
                'store' => "{$name}.store",
                'show' => "{$name}.show",
                'edit' => "{$name}.edit",
                'update' => "{$name}.update",
                'destroy' => "{$name}.destroy"
            ],
            'parameters' => [$route => $parameter],
            'except' => $except
        ];
    }
}

Then it could be

Route::resource('kunden', ClientController::class, route_resource('kunden', 'client'));
1 like
Konstruktionsplan's avatar

Thanks for the answer. In fact I always google and search for a solution before I write this. Maybe that need to optimize.

This works wonderfully, now I ask myself the question: "/kundeN/1" shows it correctly, but it must be "kunde/1" or "kunde/1/bearbeiten". Is there a trick there too?

Konstruktionsplan's avatar

Hm. Is it the right way to go? I just want to change the plural "kunden" to singular "kunde" in edit, destroy and show.

Konstruktionsplan's avatar

Then I don't quite understand. If I do it this way, then I can use the create, store, etc. method at all and get an error message: "Route [clients.create] not defined."

   Route::resource('kunden', ClientController::class)->names([
        'index' => 'clients.index',
        'create' => 'clients.create',
        'store' => 'clients.store',
        'show' => 'clients.show',
        'edit' => 'clients.edit',
        'update' => 'clients.update',
        'destroy' => 'clients.destroy'
    ])->parameters([
        'kunden' => 'client'
    ])->except([
        'create', 'store', 'update', 'destroy'
    ]);

Ah. Now i understand.

Like so Route::get(/kunde/{client_id}/bearbeiten, Controller => Class); ?

MichalOravec's avatar

How I said, don't use Route::resource, create all your routes manually.

1 like
MichalOravec's avatar

Like so Route::get(/kunde/{client_id}/bearbeiten, Controller => Class); ?

Yes like that.

1 like

Please or to participate in this conversation.