title: Passing several, optional, key/value pairs in URL with Laravel
body: <p>I am making a project management application in Larvel.  TaskController@index queries the db and return tasks. To be efficient and elegant, I want to be able to pass it several, optional, key/value pairs in the URL, like /tasks/org_id/36/status/open or /tasks/proj_id/1557/status/closed, and have it return the tasks based on those variables.  My code is below, but the problem is getting the route to be able to receive the optional key/value pairs.  Also, they shouldn't all have to all be submitted all of the time if they aren't needed.</p>
  
  <p>Route/web.php:</p>
  
  <pre><code>Route::get('/tasks/status/{status}/proj_id/{proj_id}/user_id/{user_id}/org_id/{org_id}
  /creator_id/{creator_id}', 'TaskController@index')-&gt;name('tasks.index');
  
  Route::resource('tasks', 'TaskController')-&gt;except([
      'tasks.index'
  ]);
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>class TaskController extends Controller
  {
  
      public function index($proj_id = null, $recipient_id = null, $org_id = null, $creator_id = null, $status = null)
      {
  
          $tasks = Task::where('recipient_id', auth()-&gt;user()-&gt;id)
              -&gt;when($status, function ($query, $status) {
                  return $query-&gt;where('status', $status);
              })
              -&gt;when($recipient_id, function ($query, $recipient_id) {
                  return $query-&gt;where('recipient_id', $recipient_id);
              })
              -&gt;when($public, function ($query, $public) {
                  return $query-&gt;where('public', $public);
              })
              -&gt;get();
  
          return view('tasks.index', compact('tasks'));
      }
  </code></pre>
  
  <p>How do I get the route to be able to accept a variety of optional key/value pairs?</p>