From 4b7ede0fb21c2d4b4f8dbe96a4367231cc866185 Mon Sep 17 00:00:00 2001
From: Stephan van Diepen
Date: Tue, 28 Jan 2020 15:42:53 +0800
Subject: [PATCH] Document shallow nesting
---
controllers.md | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/controllers.md b/controllers.md
index fecd558a498..ab7d2a546f1 100644
--- a/controllers.md
+++ b/controllers.md
@@ -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']);
+
### Naming Resource Routes