Laravel 5.1: How to set Route for update record

Laravel 5.1: How to set Route for update record

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Diagnosing MethodNotAllowedHttpException in Laravel 5.1 Routes

When deploying an edit form using Form::model with a PATCH request, encountering a MethodNotAllowedHttpException usually points to a mismatch between the HTTP verb sent by the browser and what your route collection expects. In Laravel 5.1, this is almost exclusively caused by how the Route facade handles method definitions versus how HTML forms submit data by default.

Your current setup defines the update endpoint as a PUT request:

Route::put('/company/update/{id}', 'CompanyMasterController@update');

However, your blade template is explicitly asking for a PATCH request:

{!! Form::model($company, [
    'method' => 'PATCH', 
    'action' => ['CompanyMasterController@update', 'id' => $company->id]
]) !!}

Laravel's routing engine matches the HTTP method strictly. If a route is defined as PUT, it will reject incoming PATCH requests, triggering the exception you are seeing. This behavior is by design in RESTful architectures, where PUT implies replacing an entire resource, while PATCH implies partial modification. While modern Laravel versions handle both gracefully or prefer POST for safety, Laravel 5.1 requires explicit alignment between your route definition and your form method.

To resolve this immediately without altering your controller logic, you must align the route definition with the form's request method. Update your routes.php file to accept PATCH:

Route::patch('/company/update/{id}', 'CompanyMasterController@update');

Alternatively, if your application logic treats updates as full replacements rather than partial patches, switching the route back to PUT is often a safer default for standard resource controllers. You would then remove the 'method' => 'PATCH' directive from your Form::model call and let Laravel's _method field handling (enabled by default in newer versions) manage it, or simply stick to PUT consistently across your stack.

Handling Hidden Fields and CSRF Protection

A common pitfall when fixing the HTTP method is neglecting how Laravel validates incoming requests. By default, Laravel protects against Cross-Site Request Forgery (CSRF) attacks by requiring a token for state-changing methods like PUT, PATCH, and DELETE.

When you use Form::model(), Laravel automatically generates this hidden input field containing the token. However, if you manually change the route or method in an attempt to bypass the error, ensure that:

  1. The CSRF meta tag is present in your layout's <head> section.
  2. The form action URL matches the defined route exactly, including the {id} segment.

If you decide to switch the route back to PUT, keep the 'method' => 'PATCH' attribute in your blade file only if you are relying on Laravel's _method field feature to rewrite the request. In Laravel 5.1, this rewriting happens automatically when a hidden _method input is detected with a value of PUT. If your form currently lacks this hidden field (which Form::model adds), switching the route to PATCH without updating the form method will still fail if the browser sends a standard PUT request but the route expects PATCH, or vice versa.

Controller Validation and Model Binding

Once the routing alignment is corrected, you should also review your controller's update method. Your current implementation uses Request::all() to grab all input data and blindly assigns it to the model:

public function update($id)
{
    $bookUpdate = Request::all();
    $book = CompanyMasters::find($id);
    $book->update($bookUpdate);
    return redirect('/company/index');
}

This approach is fragile. If your form includes hidden fields (like CSRF tokens or timestamps) that shouldn't update the database, Request::all() will try to save them, potentially causing conflicts or data corruption. A more robust pattern involves filtering the input or using a strict validation rule set before calling update().

You can filter out unwanted keys like _token and _method:

$validated = Request::except(['_token', '_method']);
$book = CompanyMasters::findOrFail($id); // Use findOrFail to prevent N+1 or silent failures
$book->update($validated);

Additionally, consider using Model Binding in the route definition. Instead of passing $id manually as a query parameter or part of the action array, you can define the route to accept a CompanyMaster model instance directly:

Route::patch('/company/update/{company}', 'CompanyMasterController@update');

In the controller, the first argument would then be the model instance itself, removing the need to manually query the database with $id. This reduces coupling between your route and your controller logic.

Conclusion

The MethodNotAllowedHttpException arises because your route expects a PUT request while your form sends a PATCH request. Correcting this requires ensuring the HTTP method in your Route::patch() or Route::put() definition matches the 'method' attribute in your Form::model blade directive. Once aligned, ensure CSRF tokens are handled correctly and consider refining your controller to filter input data before updating the model.

Our network