Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[6.x] Add shallow option for resource routes #31208
It's a good practice not to nest resources too much. Routes and their url helpers quickly get unwieldy. Shallow nesting is a way to prevent deep nesting of resources. Collection actions (index, new, create) are scoped to the parent to provide context, while member actions (show, edit, update, destroy) are placed in the root or namespace when provided. This strikes a nice balance between being descriptive and being compact. An additional advantage is that resource members have a single canonical route.
Instead of typing:
Route::resource('foo.bar', 'BarController')->only(['index', 'create', 'store']); Route::resource('bar', 'BarController')->only(['show', 'edit', 'update', 'destroy']);
We can simply type:
And have the following routes generated for us: