title: Laravel 5.2.36 MethodNotAllowedHttpException in RouteCollection.php line 218:
body: <p>Hi I am fairly new to Laravel and am trying to implement a post request for a simple form. I have been following a YouTube Tutorial series (<a href="https://www.youtube.com/watch?v=m9RIWNrWpjs&amp;list=PLzeTBm5Nhz71Z5GtN9H66iPWLbFmD0mBI#t=50.044555" rel="nofollow">laravel 5 | Section 3 | Part 4 Routing POST Requests</a>) however at 5:46mins in, there is a notification that this method is only applicable to versions prior to Laravel 5.2.</p>
  
  <p>I have tried to edit the VerifyCsrfToken.php method protected $except = ['api/']; but this makes no difference.</p>
  
  <p>My routes.php code snippet:</p>
  
  <pre><code>Route::post('/form-handler', function(\Illuminate\Http\Request $request){
      if(isset($request['option']) &amp;&amp; $request['firstName'])
      {
          if(strlen($request['firstName']) &gt; 0){
              return view('forms.formResults', ['action' =&gt; $request['option'], 'name' =&gt; $request['firstName']]);
          }
          return redirect()-&gt;back();
      }
      return redirect()-&gt;back(); // Return user back to the page they came from
  })-&gt;name('form-handler');
  </code></pre>
  
  <p>My welcome.blade.php code snippet:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;form action="{{route('form-handler')}}" method="post" class="form-control"&gt;
          &lt;label for="select-action"&gt;Select an option:&lt;/label&gt;
          &lt;select id="select-action" name="option"&gt;
              &lt;option value="option1"&gt;Option1&lt;/option&gt;
              &lt;option value="option2"&gt;Option2&lt;/option&gt;
              &lt;option value="option3"&gt;Option3&lt;/option&gt;
          &lt;/select&gt;
          &lt;input type="text" name="firstName"&gt;
          &lt;button type="submit"&gt;Submit Details&lt;/button&gt;
          &lt;input type="hidden" value="{{Session::token()}}" name="_token"&gt; &lt;!-- Laravel Security Measure, Note name must always be '_token'--&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My full error message:</p>
  
  <pre><code>MethodNotAllowedHttpException in RouteCollection.php line 218:
  in RouteCollection.php line 218
  at RouteCollection-&gt;methodNotAllowed(array('POST')) in RouteCollection.php line 205
  at RouteCollection-&gt;getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158
  at RouteCollection-&gt;match(object(Request)) in Router.php line 821
  at Router-&gt;findRoute(object(Request)) in Router.php line 691
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 675
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 246
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 49
  at Debugbar-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
  at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 132
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 99
  at Kernel-&gt;handle(object(Request)) in index.php line 53
  </code></pre>
  
  <p>Is this method of implementation completely invalid or does it just need a few tweeks?</p>
  
  <p>Preferably I would like to know what the optimal post method is for retrieving form data, while still protecting your site from cross-site request forgeries.</p>
  
  <p>Any fixes or alternate solutions will be much appreciated.</p>
  
  <p>Please feel free to ask for any resources I may have left out.</p>
  
  <p>Full routes.php (Note I have also tried adding the post method to the middleware route group):</p>
  
  <pre><code>    &lt;?php
  
  /*
  |--------------------------------------------------------------------------
  | Application Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register all of the routes for an application.
  | It's a breeze. Simply tell Laravel the URIs it should respond to
  | and give it the controller to call when that URI is requested.
  |
  */
  
  /* Route::get('/', function () {
      return view('home.welcome');
  }); */
  
  Route::get('/', 'WelcomeController@index')-&gt;name('home');
  
  Route::resource('lists', 'ListsController');
  
  Route::get('/contact/{firstName?}', function($firstName = null)
  {
      return view('about.contact', ['firstName' =&gt; $firstName]);
  })-&gt;name('contact');
  
  Route::get('/blog', function()
  {
      return view('blog.blog');
  })-&gt;name('blog');
  
  Route::group(['middleware' =&gt; 'auth'], function () {
      Route::post('/form-handler', function(\Illuminate\Http\Request $request){
          if(isset($request['option']) &amp;&amp; $request['firstName'])
          {
              if(strlen($request['firstName']) &gt; 0){
              return view('forms.formResults', ['action' =&gt; $request['option'], 'name' =&gt; $request['firstName']]); // You create the view
          }
          return redirect()-&gt;back();
      }
      return redirect()-&gt;back(); // Return user back to the page they came from
      })-&gt;name('form-handler');
  });
  </code></pre>