title: Laravel 5.1 adding middleware to resource route
body: <p>so I have been trying to use middleware with my route resource and having trouble making it work.</p>
  
  <p>Here is my routes setup:</p>
  
  <pre><code>Route::group(['prefix' =&gt; 'api','middleware' =&gt; 'locationRouteValidator'], function()
  {
      Route::resource('location', 'LocationController');
  });
  </code></pre>
  
  <p>and route seems to be setup properly: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>php artisan route:list
  +--------+----------+------------------------------+----------------------+-------------------------------------------------+------------------------+
  | Domain | Method   | URI                          | Name                 | Action                                          | Middleware             |
  +--------+----------+------------------------------+----------------------+-------------------------------------------------+------------------------+
  |        | GET|HEAD | /                            |                      | Closure                                         |                        |
  |        | GET|HEAD | api/location                 | api.location.index   | App\Http\Controllers\LocationController@index   | locationRouteValidator |
  |        | POST     | api/location                 | api.location.store   | App\Http\Controllers\LocationController@store   | locationRouteValidator |
  |        | GET|HEAD | api/location/create          | api.location.create  | App\Http\Controllers\LocationController@create  | locationRouteValidator |
  |        | DELETE   | api/location/{location}      | api.location.destroy | App\Http\Controllers\LocationController@destroy | locationRouteValidator |
  |        | PATCH    | api/location/{location}      |                      | App\Http\Controllers\LocationController@update  | locationRouteValidator |
  |        | GET|HEAD | api/location/{location}      | api.location.show    | App\Http\Controllers\LocationController@show    | locationRouteValidator |
  |        | PUT      | api/location/{location}      | api.location.update  | App\Http\Controllers\LocationController@update  | locationRouteValidator |
  |        | GET|HEAD | api/location/{location}/edit | api.location.edit    | App\Http\Controllers\LocationController@edit    | locationRouteValidator |
  +--------+----------+------------------------------+----------------------+-------------------------------------------------+------------------------+</code></pre>
  </div>
  </div>
  </p>
  
  <p>so now I create the middleware :</p>
  
  <pre><code>php artisan make:middleware locationRouteValidator
  </code></pre>
  
  <p>and leave the default code, which is :</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      return $next($request);
  }
  </code></pre>
  
  <p>and just for testing, in my controllers show method, I echo out the passed id like so:</p>
  
  <pre><code>public function show($id)
  {
      //
      echo "show ".$id;
  }
  </code></pre>
  
  <p>so now I expect that when I visit <code>/public/api/location/abcd</code> it should display:
  <code>show abcd</code> or when I visit <code>/public/api/location/1234</code> it should display <code>show 1234</code> after which I intended to modify the middleware to allow only numeric values to be passed into <code>{location}</code>.</p>
  
  <p>But If I just run with the default middleware code, the page returns white without displaying anything. I remove the middleware from the route, and it displays the text as expected.</p>
  
  <p>I know I could attach the middleware to the controller instead, but I thought of attaching it in the route instead so that I could write and apply some common middleware by using the route's group feature, which should be possible, right?</p>
  
  <p>Where do you guys think I am going wrong? Thanks in advance for looking!</p>