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

stratboy's avatar

A way to customize resource routes?

Hi, I mean:

Route::resource('seeds', SeedController::class);

Say that I'd like GET seeds/create to be seeds/share or say, seeds/give. Is there a way? Or I should just manually write that route, and therefore use a partial resource route for the others?

0 likes
6 replies
LaryAI's avatar
Level 58

Yes, you can customize your resource routes in Laravel by using the names array in the options parameter of the Route::resource method. You can also exclude certain routes from the resource controller using the except method if you want to define them manually with a different name. Here's how you can do it:

Route::resource('seeds', SeedController::class)->except([
    'create'
]);

Route::get('seeds/share', [SeedController::class, 'create'])->name('seeds.share');

In this example, we're excluding the create method from the resource routes, and then we're manually defining a GET route with the URI seeds/share that points to the create method in the SeedController. We also give it a name of seeds.share so you can refer to it using the route name in your application.

If you want to rename other resource routes, you can pass an array to the names option like this:

Route::resource('seeds', SeedController::class)->names([
    'create' => 'seeds.share',
    'edit' => 'seeds.modify',
    // other custom names for your resource routes
]);

This will rename the create and edit routes to seeds.share and seeds.modify respectively, while keeping the rest of the resource routes with their default names. Remember to update your controller method names accordingly if you choose to rename them.

Tray2's avatar

I'm not saying you can't, but you should stick with the conventions, it will save you a lot of headache later on.

stratboy's avatar

@Tray2 Hi, thank you. I'd simply like to have a route like

seeds/give that points to SeedController->create. So I don't want to change the controller method, nor I need to change the view name. Just the url. That's because I'm building a seed savers website, in Italy, so I need simple and Italian urls, suitable for people not so used to technology.

Is it really dangerous with Laravel doing such a thing? I'm used with Wordpress, which lets you create all sorts of custom routes, permalinks, pretty url, whatever you call them, whichever you want or like, if needed, without any particular issue.

Bogey's avatar

@martinbean I appreciate you actually providing an answer rather than pushing the convention idealogy.

1 like

Please or to participate in this conversation.