title: Laravel - How can I used a different controller based on url parameters?
body: <p>I have a route that looks like this:</p>
  
  <pre><code>Route::get('/{camp}/session/{session}/athlete/{athlete}/category/{category}/type/{type}', 'AthleteController@chart');
  </code></pre>
  
  <p>This page renders a view that allows an athlete to choose the position (Kicker, Punter, Receiver etc). The "Position" is the <code>/type/{type}</code> part of the url. Based on the value of <code>{type}</code> If possible, I would like to use the appropriate controller. </p>
  
  <p>For example, let's say <code>/type/2</code> is Kickoff. So to show the kickoff form this url:</p>
  
  <pre><code>/camp/123/session/456/athlete/5/category/1/type/2
  </code></pre>
  
  <p>Would use <code>KickoffController@create</code>. Then the <code>KickoffController@store</code> to save the data.</p>
  
  <p><code>/type/3</code> would be for punting:</p>
  
  <pre><code>/camp/123/session/456/athlete/5/category/1/type/3
  </code></pre>
  
  <p>So I would use <code>PuntController@create</code>; <code>PuntController@store</code> to save (and so on).</p>
  
  <p>I suppose I could create a <code>StatController</code> and just keep expanding a switch based on type, but that seems...not as clean as having a 1:1 stat:controller.</p>
  
  <p>I've looked around at dynamic routing. Is that I what I need here?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is what my form tag looks like using <code>Laravel Collective</code>:</p>
  
  <pre><code>{!! Form::open(array('action'=&gt;'KickoffController@store','class'=&gt;'charting-form')) !!}
  </code></pre>
  
  <p>Here is what I have tried based on the suggested answer and some other SO posts. (please keep the laughter to a minimum) :)</p>
  
  <pre><code>Route::post('/{camp}/session/{session}/athlete/{athlete}/category/{category}/type/{type}/store', function ($type) {
  
      switch ($type) {
          case 1:
              $stat = 'Kickoff';
              break;
          default:
              break;
      }
  
      $class = 'App\Http\Controllers\/' . $stat . '\/Controller';
      $action = 'method';
  
      if (method_exists($class, $action . 'Action')) {
          $controller = App::make($class);
          return $controller-&gt;callAction($action, array());
      }
  });
  </code></pre>