title: Shallow a group of routes in Laravel
body: <p>According to the Laravel docs about &quot;Nested Resources&quot;,</p>
  <blockquote>
  <p>Sometimes you may need to define routes to a nested resource. For
  example, a photo resource may have multiple comments that may be
  attached to the photo. To nest the resource controllers, you may use
  &quot;dot&quot; notation in your route declaration:</p>
  </blockquote>
  <pre><code>use App\Http\Controllers\PhotoCommentController;
   
  Route::resource('photos.comments', PhotoCommentController::class);
  </code></pre>
  <p>This route will register a nested resource that may be accessed with URIs like the following:</p>
  <pre><code>/photos/{photo}/comments/{comment}
  </code></pre>
  <p>But again according to laravel,</p>
  <blockquote>
  <p>Often, it is not entirely necessary to have both the parent and the
  child IDs within a URI since the child ID is already a unique
  identifier. When using unique identifiers such as auto-incrementing
  primary keys to identify your models in URI segments, you may choose
  to use &quot;shallow nesting&quot;:</p>
  </blockquote>
  <pre><code>use App\Http\Controllers\CommentController;
   
  Route::resource('photos.comments', CommentController::class)-&gt;shallow();
  </code></pre>
  <p>So far everything is good. Now imagine I have projects and a single project may have multiple users, multiple tasks, multiple vendors etc.</p>
  <p>If I want to shallow all the users, tasks and vendors in a route group, and don't want to call <em>shallow</em> method again and again, how can I achieve this?</p>
  <p>Current routing structure:</p>
  <p><a href="https://i.stack.imgur.com/M3BbA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M3BbA.png" alt="enter image description here" /></a></p>
  <p>Expected routing structure, something like this as Laravel did not provide any helpful guide on shallowing a group of routes:</p>
  <p><a href="https://i.stack.imgur.com/bF5zb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bF5zb.png" alt="enter image description here" /></a></p>