title: Laravel nested route model binding
body: <p>I am developing an API using Laravel for use with a mobile app and am having some issues with Route Model Binding on nested routes.
  The app will have a standalone sqlite db which will synchronise client journeys with the central server when network is available. For that reason, the PK's in the app cannot be used to access the records on the central server. Each user will have a unique username which will be stored on the central server in a table with the following columns:</p>
  
  <blockquote>
    <ul>
    <li>user_id </li>
    <li>username</li>
    </ul>
  </blockquote>
  
  <p>The journey table will then have the following columns:</p>
  
  <blockquote>
    <ul>
    <li>journey_id</li>
    <li>user_id</li>
    <li>user_journey_id</li>
    </ul>
  </blockquote>
  
  <p>where the <code>user_journey_id</code> will be the PK of the journey record on the client device.
  The idea is that the clients can then access the api with something like:
  <a href="http://example.com/api/client/UNIQUE_USERNAME/journey/1234" rel="nofollow">http://example.com/api/client/UNIQUE_USERNAME/journey/1234</a>
  to retrieve the journey from the central server.</p>
  
  <p>I have the following resources setup:</p>
  
  <pre><code>Route::resource('client','ClientController');
  Route::resource('client.journey','JourneyController');
  </code></pre>
  
  <p>and have setup route model binding successfully for the client as follows:</p>
  
  <pre><code>$router-&gt;bind('client', function($value, $route) {
      return \App\Client::where('username', '=', $value)-&gt;firstOrFail();
  });
  </code></pre>
  
  <p>I'm having a bit of trouble with setting up the nested model binding as I require the client <code>username</code> in combination with the <code>user_journey_id</code> to retrieve the correct journey. Is there a way to do this with route model binding? <br/>
  Or should this just be done in the controller with some like:</p>
  
  <pre><code>public function show(Client $client, $user_journey_id)
  {
     ... // have logic here to get the journey.
  </code></pre>
  
  <p>This is how I do it currently but the route model binding would certainly make it a bit easier.</p>