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

mrsafalpiya's avatar

Resource route suffix

Hello! Hope you are having a wonderful day. I encountered a little hiccup with resource routing and couldn't find a solution online, so I thought I'd seek some guidance here. Here's a bit of context for my problem:

I have a SchoolGradeController set up as a resource controller, and I'd like to register routes within this controller as follows:

  • GET /schools/{id}/grades
  • POST /schools/{id}/grades

In essence, I want to register the controller under the /schools route but append grades suffix.

Any help or pointers you could offer would be truly appreciated. Thank you so much in advance for your time and assistance!

Wishing you a fantastic day ahead!

0 likes
4 replies
Tray2's avatar

Just wrap it with a group.

Route::prefix('something')->group(function() {
        Route::resource('users', Usercontroller::class);
});

Gives

GET|HEAD        something/users ................................................... users.index › Usercontroller@index
  POST            something/users ................................................... users.store › Usercontroller@store
  GET|HEAD        something/users/create .......................................... users.create › Usercontroller@create
  GET|HEAD        something/users/{user} .............................................. users.show › Usercontroller@show
  PUT|PATCH       something/users/{user} .......................................... users.update › Usercontroller@update
  DELETE          something/users/{user} ........................................ users.destroy › Usercontroller@destroy
  GET|HEAD        something/users/{user}/edit ......................................... users.edit › Usercontroller@edit
1 like
mrsafalpiya's avatar

@Tray2 Thanks for your reply. Correct me if I'm wrong but I don't think this will give me a route as /schools/{school}/grades.

Tray2's avatar
Tray2
Best Answer
Level 73

@mrsafalpiya It would if you add it to the group

Route::prefix('something/{something_too}')->group(function() {
        Route::resource('users', Usercontroller::class);
});
GET|HEAD        something/{something_too}/users ................................... users.index › Usercontroller@index
  POST            something/{something_too}/users ................................... users.store › Usercontroller@store
  GET|HEAD        something/{something_too}/users/create .......................... users.create › Usercontroller@create
  GET|HEAD        something/{something_too}/users/{user} .............................. users.show › Usercontroller@show
  PUT|PATCH       something/{something_too}/users/{user} .......................... users.update › Usercontroller@update
  DELETE          something/{something_too}/users/{user} ........................ users.destroy › Usercontroller@destroy
  GET|HEAD        something/{something_too}/users/{user}/edit ......................... users.edit › Usercontroller@edit
1 like

Please or to participate in this conversation.