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!
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
@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.
@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
@Tray2 This is exactly what I was looking for. Thanks!
Please sign in or create an account to participate in this conversation.