Skip to content

[6.x] Document shallow nesting #5750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ Sometimes you may need to define routes to a "nested" resource. For example, a p

This route will register a "nested" resource that may be accessed with URLs like the following: photos/{photos}/comments/{comments}.

#### Shallow Nesting

Shallow nesting is a way to keep nested resources of getting too verbose. Collection actions are scoped to the parent while member actions are placed at the root. This provides a sense of context while keeping routes succinct.

Route::resource('photos.comments', 'CommentController')->shallow();

This will register nested routes for `index`, `new` and `create` with URLS like: photos/{photo}/comment. For `show`, `edit`, `update` and `destroy` shallow routes are created like: comments/{comment}.

It's basically a convenient shorthand for:

Route::resource('photos.comments', 'CommentsController')->only(['index', 'create', 'store']);
Route::resource('comments', 'CommentsController')->only(['show', 'edit', 'update', 'destroy']);

<a name="restful-naming-resource-routes"></a>
### Naming Resource Routes

Expand Down