Laravel error: MethodNotAllowedHttpException in RouteCollection.php display

Posted on

An error can be generated when a script based on Laravel framework powered by PHP is executed. The error as specified in the title, ‘MethodNotAllowedHttpException’ is presented where the trigger shows up in file named RouteCollection.php specifically on this context it is in line 218.

So, just in case that the error is actually the one you are looking for and it is becoming a similar cause with the error you are facing right now this article is written to inform it.

The error can be viewed in the following image :

The cause for the above generated error is the following script based on Laravel framework powered by PHP in a certain script of view in form of Blade Template view located in resources/view as follows :

<?php
echo Form::open(array('url' => 'server/store', 'method' => 'POST'))
?>

The above snippet code is a code which is defined to create a Form in order to send all the data inserted in the field form to be processed in a URL defined as ‘server/store’. Moreover the URL can be any kind of URL depends on the circumstance of the application. It is somehow based on Laravel rules defined in a file functioned as a router definition allowing any forms or URL defined to be processed and to be redirected into a certain location defined. For an example, it is defined as follows :

Route::resource('server','ServerController');

It is defining a RESTful resource controller which is creating some default routes and even adding the name for it as follows :

Verb    Path                        Action  Route Name
GET     /server                     index   server.index
GET     /server/create              create  server.create
POST    /server                     store   server.store
GET     /server/{server}            show    server.show
GET     /server/{server}/edit       edit    server.edit
PUT     /server/{server}            update  server.update
DELETE  /server/{server}            destroy server.destroy

Controller is a file created in Laravel framework dedicated to define processes for the application. On the blade template file dedicated for defining the view, there is a declaration for creating a form. And the form has a certain rules in the definition. It only can support ‘GET’, ‘HEAD’, ‘PUT’, ‘PATCH’, ‘DELETE’. So, the above definition generated error is because the for definition contains not one the permitted method available. Just change it into one of the method permitted as shown follows :

<?php
echo Form::open(array('url' => 'server/store', 'method' => 'PUT'))
?>

The form will be submitted into the following URL named ‘server/store’ with method ‘PUT’.

One thought on “Laravel error: MethodNotAllowedHttpException in RouteCollection.php display

Leave a Reply